Trying to dynamic include HTML into a JSP

All,
I am trying to include an HMTL file into a JSP file. I wish to do this dymanically. So, the following is not an option:
<%@ include file="relativeURL" %>
So, I am forced to resort to such measures as the following:
<jsp:include page="<%=myPath%>"/>
However, I get the following error:
java.lang.IllegalStateException: Response has already been committed
     at java.lang.Throwable.fillInStackTrace(Native Method)
     at java.lang.Throwable.fillInStackTrace(Compiled Code)....
I tried it like this:
<jsp:include page="<%=myPath%>" flush="true"/>
I encoutered the same result. I have JSP 1.2 running Tomcat 3.1 with Apache 1.3.14, all on SunOS. Thanks in advance for any help.
Nicholas

One of the worst error messages you can get is the IllegalStateException. It simply means that an attempt has been made to forward or include but only a portion of the include was sent. In a situation like this the best way to handle the dynamic page content is to include it from a Servlet by sending the information you need through beans. Including the Servlet rather than the dynamic path would clear those errors right up. One thing to keep in consideration is that you can't just get the page and display it, you have to buffer it in so the state can be kept alive without timing out like it does with the dynamic include.
Hope that helps. Been there, done that, I know how frustrating the error was.

Similar Messages

  • How to include HTML file in JSP using HTML elements or Javascript?

    Hi,
    I have around 15000 static html files one for each item which we display each upon invoking an item.The HTML file should be part of a JSP file.
    Please note that the name of the HTML file is determined dynamically
    Placing all the HTML files within the web application does not give us good performance so i would like to put all of them in the webserver.
    I am not able to include the file in the JSP using the jsp:include attribute if i place the HTML files in the webserver ,
    in order to do that i think should use either HTML element or javascript to include the HTML in the JSP.is there any alternative to <Jsp:include>
    Does anyone have an idea how to include the HTML file and take advan tage of webserver?
    Any ideas are appreciated

    What you need to do is simply read the HTML file from the disk and dump it out to the outputstream. It really is that simple.
    There's no reason you need to include all 15000 files in the actual WAR, you can place those files any place handy that is easy for the application to see (in another directory, or accessible from a file server if you have multiple front ends).
    Then, just write a utiility function that takes the output stream (i.e. the 'out' JSP variable), and the file name, read the file, and write it to the stream.
    If you start noticing performance issues, then you can try doing some caching, but truth is your OS should be doing that for you.
    But, truth be told that's the only practical way to do it.
    Another solution would be to use JavaScriipt and XMLHttpRequest (i.e "AJAX") to load the file at the client side, and simply replace a tag with the results.
    That's also pretty trivial to write, any web site talking about AJAX should give you hint there.
    Of course, that won't work for folks who have JavaScript turned off, or some other incompatible browser, whereas the server side solution obviously works everywhere.

  • Including JavaScript into a JSP Page

    Hi,
    How do i include a piece of JavaScript <SCRIPT> stuff into a JSP Page?
    Right now i have an HTML Page that includes some <SCRIPT> code. Now many other HTML files use this piece of <SCRIPT> stuff. How do i remove it , put it in one place(I mean where to put it and what would that file be called) and in a JSP page call this <SCRIPT> code?
    Please help . i'm pretty new to JSP and JavaScript.
    Thanks in Advance.
    Phani
    /**** CODE
    <SCRIPT language=javascript>
    <!--
         if ((document.images) && ("Netscape" != navigator.appName) && (navigator.appVersion.indexOf('Mac') == -1))
         document.write("<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"http://www.telia.se/tews/css/1.css\">");
         else if ((document.images) && ("Netscape" != navigator.appName) && (navigator.appVersion.indexOf('Mac') > 1))
         document.write("<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"http://www.telia.se/tews/css/5.css\">");
         else if (("Netscape" == navigator.appName) && (parseInt(navigator.appVersion) == 4) && (navigator.appVersion.indexOf('Mac') == -1))
         document.write("<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"http://www.telia.se/tews/css/2.css\">");
         else if (("Netscape" == navigator.appName) && (parseInt(navigator.appVersion) == 4) && (navigator.appVersion.indexOf('Mac') > 1))
         document.write("<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"http://www.telia.se/tews/css/3.css\">");
         else if (("Netscape" != navigator.appName) && ("Microsoft Internet Explorer" != navigator.appName))
         document.write("<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"http://www.telia.se/tews/css/6.css\">");
    // -->
    </SCRIPT>

    Ok, first let us make clear the demarcation between java and javascript.
    Java runs on the server, and produces an HTML page which is sent to the client.
    That HTML page may contain javascript code on it to run on the client side.
    As the page is loaded, javascript may be compiled/run on the client.
    So you have some javascript code which you want to include on every page as template text?
    I would do this in JSP by using the include directive to add that bit of template text to every single JSP page.
    ie
    header.jspf
    <SCRIPT language=javascript>
    <!--
    if ((document.images) && ("Netscape" != navigator.appName) && (navigator.appVersion.indexOf('Mac') == -1))
    document.write("<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"http://www.telia.se/tews/css/1.css\">");
    else if ((document.images) && ("Netscape" != navigator.appName) && (navigator.appVersion.indexOf('Mac') > 1))
    document.write("<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"http://www.telia.se/tews/css/5.css\">");
    else if (("Netscape" == navigator.appName) && (parseInt(navigator.appVersion) == 4) && (navigator.appVersion.indexOf('Mac') == -1))
    document.write("<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"http://www.telia.se/tews/css/2.css\">");
    else if (("Netscape" == navigator.appName) && (parseInt(navigator.appVersion) == 4) && (navigator.appVersion.indexOf('Mac') > 1))
    document.write("<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"http://www.telia.se/tews/css/3.css\">");
    else if (("Netscape" != navigator.appName) && ("Microsoft Internet Explorer" != navigator.appName))
    document.write("<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"http://www.telia.se/tews/css/6.css\">");
    // -->
    </SCRIPT>
    <noscript>
      // stuff here for when the browser does not support javascript
    </noscript>And then in every jsp page
    <%@ page include="header.jspf" %>
    // rest of the JSP pageThe file "header.jspf" will be included with every jsp page served, and you only need to update that page in one place.
    If you have a JSP2.0 container you can define a jsp prelude which will be the same as having the <%@ page include="header.jspf" %> on every page.
    You do this in the web.xml file:
    Something like this:
      <jsp-property-group>
         <url-pattern>*.jsp</url-pattern>
         <include-prelude>/WEB-INF/jspf/prelude1.jspf</include-prelude>
      </jsp-property-group>The specified file will be loaded into every JSP page without the JSP page having to define the import itself.
    Hope this helps,
    evnafets

  • Include html content in jsp

    Hi ,
    I have the html data and need to include in the jsp .
    eg :
    String htmldata = " <html><body>testdata </body></html>";
    how can i display this htmldata in the jsp . I mean I need this data in html format ( testdata ) and should not see all html tags in the explorer.
    Suggest me if you know anything.
    Thanks in advance.
    - bregoty

    You have the right idea, but you need to specify the escapeXml attribute on the c:out tag to be false. It defaults to true, and this means that when c:out encounters special characters it tries to display as-is rather, which is why you saw your HTML formatting. Set the escapeXml attribute to false and this should solve your problem.
    <table width=100% cellspacing=0 cellpadding=5>
         <c:forEach items="${myBean}" var="myDB">
         <tr height=10px>
              <td>
                   <c:out value="${myDB.htmldata}" escapeXml="false" />
              </td>
         </tr>
    </table>

  • Trying to dynamically add TextInput into HGroup, need some help

    Hey all, I am trying to add a TextInput instance into an HGroup instance all in actionscript, but I am getting an error (implicit coersion, unrelated type to IVisualElement). Doesn't the TextInput class implement the IVisualElement Interface?? Here is a snippit of my code:
    var myHG:HGroup = new HGroup();
    var myTI:TextInput = new TextInput();
    myHG.addElement(myTI); // gives me the error
    However, when I dynamically create radiobuttons, I have no prob adding them to my hgroup??  any ideas of what I am doing wrong??

    UIComponent in flex 4 (and later) implements IVisualElement, so that error is unexpected. If you have a small test case then log a bug at http://bugs.adobe.com/jira
    -Gaurav
    http://www.gauravj.com/blog

  • Trying to dynamically populate html:options

    I am using iframe.
    on the first frame the user inputs letters and the database is searched for anything that starts with those letters.
    <html:text property="usersInput"/>
    <html:submit value="search" onclick="middle.document.forms[0].property='list'"/>
    the second frame "middle" is suppose to display the results of the search.
    html:select property="list">
    <html:options property="list"/>
    </html:select>
    of course with this code the second frame "middle" gives an err msg, because list is null.
    Is there anyway to get around this so that initially the select list that appears on the pages is empty and then when the search is done (button is clicked) the list will populate with the results?

    I guess there must be something wrong with my question :( no one is helping me. Well let me ask this...
    With formbeans and iframes...
    Is the information process while in the <html:form>...</html:form> or once it leaves the form? because now I'm doing the search in one frame and then onclick="..." I'm calling another frame to display the results of the search using <html:select><html:options>...</html:select>, but I keep getting an err msg "null pointer".
    It seems like the information from the first iframe, either has not been "processed" or got "deleted" by the formbean, when the second frame tries to access it.
    Can someone please give me an idea of what's going on. I'VE HIT A WALL!!!!

  • Dynamic include in a custom tag, called from a jsp

    Hello, I would like to be able to dynamically include other jsp's from within a custom tag that I create. is this possible?
    in a jsp page i would just write <%@ include file="file.jsp" %> and all would be ok... but if i do an out.println( "<%@ include file=\"file.jsp\" %>" ); inside a custom tag bean then it doesn't work. it just prints out the command to the page as plain text.
    I do understand why this is happening, but can anyone offer me a way around this problem?
    Thanks in advance,
    Randy

    That's actually the same result as you get with a normal include - The method I suggested is a dynamic include similar to the <jsp:include> tag, not the <%@ include %> tag.
    When you use a dynamic include, the included page is compiled and 'invoked' as serarately, and the result is what gets included, not the actual source. To get the behaviour you want would require an include directive (the <%@ include %> tag) which I don't think has an equivalence you can use inside a custom tag.
    What you can do is pass attributes from the tag class like this:
    pageContext.setAttribute(<name>, <object>, pageContext.REQUEST_SCOPE);
    and then remove them after the include using pageContext.removeAttribute.
    I'm not certain, but this implies that if you declare your variables with a <jsp:usebean> tag with request scope, instead of normal Java variable declarations, you should be able to use them in the page included by the custom tag.
    *** in the jsp ***
    <jsp:useBean id="myVar" scope="request" class="java.lang.String" />
    <% myVar = "Something"; %>
    // Now call the tag which uses the pageContext.include() mehtod.
    *** end ***
    *** in the include ***
    <jsp:useBean id="myVar" scope="request" class="java.lang.String" />
    <%= myVar + " something else" %>
    *** end ***
    Let me know if it works.

  • How include a Servlet into a JSP page?

    Hi!!
    I need make a combobox with a servlet and place its result into a jsp page.
    The servlet is in a package, but when i do: <jsp:include file="sic.view.servlet.ComboServlet" />
    tell me that "file attribute isn�t a valid attribute name"
    whow can i do to make the combobox whit the servlet and include this into the jsp page??
    Thanks!!
    PD: Sorry my pour English...

    Servlets should be mapped to a URL, then you access the servlet via that URL.
    The servlet mapping is done in the web.xml (in WEB-INF/ directory of your web application)
      <servlet>
        <servlet-name>
          Combo_S
        </servlet-name>
        <servlet-class>
          sic.view.servlet.ComboServlet
        </servlet-class>
      </servlet>
      <servlet-mapping>
        <servlet-name>
          Combo_S
        </servlet-name>
        <url-pattern>
          /combo
        </url-pattern>
      </servlet-mapping>Then you would use:
    <jsp:include file="combo" />
    to include it.
    Make sure the class file gets put in the right package under WEB-INF/classes/

  • How to include .js file in jsp file?

    hi,
    i have a jsp file with struts tag. right now i have all the javascript code as a separate function inside the jsp file itself. i want the javascript code to be present in a .js file and i want to refer that .js file from the jsp file with struts tags.
    <html:text property="Phone" value="" size="3" maxlength="3"
         onkeyup="return autoTab(this, 3, event);"></html:text>
    the above is the html tag which will call the function "autoTab" of the .js file. please help.
    thanks,
    Jayanth.

    You include javascript into a jsp in exactly the same way you do with html
    <script src="myJavascriptFile.js"/>
    It has nothing to do with the jsp per se, but rather the generated HTML page.

  • How to upload an html file using jsp and jdbc

    Hi,
    im trying to upload an html page using JSP and jdbc. but of no success.
    my aim is to keep some important html pages in the database.the file size can vary.the file has to be selected from a local machine (through the browser) and uploaded to a remote machine(where the databse resides).
    any help/sample code or pointer to any helpful link is appreciated.
    thanks in advance
    javajar2003

    When uploading a file, I use a byte array as a temporary buffer..
    So, you should then be able to store the byte array in the
    database as binary data.
    example>
    //Temporary Buffer To Store File
    byte[] tmpbuffer = new byte[860];
    //Some Code To Upload File...
    //File Should Now Be In Byte Array
    //Get DB Connection and execute Prepared Statement
    Connection con=//GET DB CONNECTION;
    String sql=insert into TABLE(page) values(?);
    PreparedStatement ps=con.prepareStatement(sql);
    ps.setBytes(1,tempbuffer);
    ps.executeUpdate();
    //Close PS and Free DB Connection
    ..... and this method looks like you dont even have
    to store the file in a byte array, you can just give
    it the input stream.
    ps.setBinaryStream(int, inputStream, int);
    You may have to make several attempts at this. I have
    uploaded a file and temporarily stored it in a byte array,
    but have never from there stored it in the DB as binary
    data.. but this looks like it'll work.
    Good Luck!

  • Inserting html into a composition in muse

    Hi, I am trying to insert some html into a composition in Muse.  I would like to have a clickable button trigger, and then a kind of overlay opens up with an interactive calculator inside.  I have the html for the calculator, the problem is no matter how I try to insert it into Muse, the calculator either disappears (as well as the trigger) for some reason, or the calculator stays on the page the entire time, losing the whole clickable effect.
    Can someone tell me the best way to do this?

    Hello,
    Which Composition are you trying to Use ? Blank,Featured News, Lightbox Display, Presentation or Tooltip ?
    Also Make Sure to drag and drop the inserted HTML window over the target (Border of target gets activated once you move it over), Hopefully this will work.
    I created the same using Tooltip composition and its working fine. Please take a look at the link.
    Home
    If it do not work then please share the calculator HTML  code that you are inserting so that I can do some test at my end.
    Regards
    Vivek

  • Referencing static html pages from jsps...

              Hi,
              This is probably a very simple thing to solve, but I'm having problems with referencing
              html pages from jsps under Weblogic.
              I get Error 404 - not found, whenever I try something like this in a JSP...
              <frame name="title" src="title.html" scrolling=no>
              The title.html file has definitely been copied into my ear file, and yet it isn't
              found. I can solve the problem by turning title.html into a jsp and registering
              it in web.xml. But this seems like serious overkill with static content!!
              Am I missing something really simple here?
              

              I've worked it out - directory mistake...
              Thanks,
              Chris
              "Matt Krevs" <[email protected]> wrote:
              >it sounds like a relative pathing problem
              >
              >is title.html reachable if you enter its address in the browser?
              >
              >is title.html in the same directory as your jsp?
              >
              >perhaps you could post your web.xml file?
              >
              >"Chris Sceats" <[email protected]> wrote in message
              >news:3d9c41b5$[email protected]..
              >>
              >> Hi,
              >>
              >> This is probably a very simple thing to solve, but I'm having problems
              >with referencing
              >> html pages from jsps under Weblogic.
              >> I get Error 404 - not found, whenever I try something like this in
              >a
              >JSP...
              >>
              >> <frame name="title" src="title.html" scrolling=no>
              >>
              >> The title.html file has definitely been copied into my ear file, and
              >yet
              >it isn't
              >> found. I can solve the problem by turning title.html into a jsp and
              >registering
              >> it in web.xml. But this seems like serious overkill with static content!!
              >>
              >> Am I missing something really simple here?
              >
              >
              

  • Include jspf into included jsp

    Hi all,
    I'm trying to include three pages in cascade mode: index.jsp include defaultColumn.jsp, defaultColumn.jsp include news.jspf.
    I've included this page using jsp:include tag for dynamic including.
    Including news.jspf seems not interpretate the jsp code inside, this is a part of HTML code get in browser:
    <div id="destro">
        <div class="news">
            <a class="init">Login</a>
            <form>
                <ul>
                    <li class="login"><a>Username: </a><a><input type="text" name="username" style='width : 70px; height : 15px;'></a></li>
                    <li class="login"><a>Password: </a><a><input type="text" name="pwd" style='width : 70px; height : 15px;'></a></li>
                    <li class="login"><a><input style='width: 80px;' type="submit" value="Ok"></a>
                </ul>
            </form>
        </div>         
    <!-- START OF news.jspf included -->*
    <%@ page pageEncoding="ISO-8859-15" %>
    <%
                dto.news news = new dto.news();
                int newsInPage = 3;
                String titolo[] = new String[newsInPage];
                String id[] = new String[newsInPage];
                int i = 0;
                while (i < newsInPage) {
                    titolo[i] = news.getNews(i + 1).getTitle();
                    id[i] = news.getNews(i + 1).getId();
                    i++;
                i = 0;
    %>
    <div class="news">
        <a class="init">Notizie</a>
        <ul>
            <% while (i < newsInPage) {
            %><li class="newsli"><a href="/index.jsp?command=&<%= id[i] %>"><%= titolo[i] %></a></li>
            <% i++;
            %>
            <li class="newsli"><a class="link" href="#">Altre News</a></li>
        </ul>
    </div>   
    <!-- END OF news.jspf included -->*   
    </div>Do you know where is the problem?
    Thanks a lot, Ebolo.

    The server won't compile/run a jspf file like a jsp (although you could change the configuration to make it do that)
    .jspf files are intended for inclusion using the <%@ import %> directive.
    Any targets you use with <jsp:include> should probably be "jsp"
    That will evaluate that page seperately, and the include the result of executing that page into the "parent" page.
    Cheers,
    evnafets

  • Include a Servlet into a JSP page

    Hi guys,
    When i try to include a Servlet into my JSP, the execution of the JSP stops...Somebody know why???

    Hi guys,
    When i try to include a Servlet into my JSP,the
    execution of the JSP stops...Somebody knowwhy???
    No, and do you know why ? Bcos including a
    servlet
    in
    a jsp doesnt stop the execution of the jsp. Sotell
    us that you tried to do, post some relevant
    code,
    for us to help you.
    ram.<%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <%@page buffer="500kb"%>
    <html>
    <head><title>JSP Page</title></head>
    <body>
    <jsp:include page="/showCryptValue"
    ptValue" flush="true" />
    asdfasdfasdfasdfasdf
    </body>
    </html>
    that's the source code....do you have any idea????
    Thak's a lottttFrom linxpda:
    1) setting the flush="false" parameter for thejsp:include tag?
    Here is the problem that I, and perhaps linxpda,
    think you have:
    You get an exception in the servlet.
    You have already written to and flushed the response,
    therefore you can not see the exception on your
    screen (seeing the exception on screen requires a
    send redirect to the error page, which can't happend
    when the response is already committed).
    The exception that is occuring MAY be alreay written
    in your logs, take a look.
    To see the problem on screen so as to be able to
    identify it, make sure your include tag DOES NOT
    flush the buffer. That means change
    <jsp:include page="/showCryptValue" flush="true" />
    to
    <jsp:include page="/showCryptValue" flush="false" />Hi!
    No even setting flush false or true it works...If somebody have done this before tell me how have you did....If you can post your code!
    []'s
    Falow

  • How can i render a dynamic html file in jsp page

    Hi everybody,
    i am trying to render a dynamic html file in jsp page with the result of querying a database.
    The response of the query is a xml document. And i have a stylesheet to transfer it to html.
    How can i render the html in a jsp file?

    I am using below code for HTML files
    private var appFile:String="index.html";
    if (StageWebView.isSupported)
                        currentState = "normal";
                        webView.stage = stage;
                        webView.viewPort = new Rectangle( 10, 130, (stage.stageWidth)-20, 750 );
                        var fPath:String = new File(new File("app:/assets/html/aboutus/"+ appFile).nativePath).url; 
                        webView.loadURL(fPath);
                        addEventListener(ViewNavigatorEvent.REMOVING,onRemove);
                    else {
                        currentState = "unsupported";
                        lblSupport.text = "StageWebView feature not supported";
    above code is working fine for me.

Maybe you are looking for