This discussion is archived
1 Reply Latest reply: Apr 12, 2013 12:05 AM by gimbal2 RSS

how to insert jsp from javacode into another jsp

malky Explorer
Currently Being Moderated
Hi, i'm working on legacy code so please don't start "why are you doing it that way", I know it's terrible implementation so lets skip that.

In a high level I have a JSP
<html:form action="/myAction" method="POST" onsubmit="beforeSubmit()">
...
              <table class="dialog">
                   <% render.myhtml(out); %>
              </table>
...
</html>
render.myhtml(out) is in the java code as follows (i tried with both jsp:include and @ include :
public void myhtml(Writer w) throws IOException {
    ....
            String include = "<jsp:include page=" +"\"" +myobject.getPage() +"\"" + " />";
           //String include = "<%@ include file=" +"\"" +myobject.getPage() +"\"" + " %>";
            println(w, include);
    ...
}
but when I open the page I cannot see the include.. the source code shows that it's printing the include tag but not evaluating it:
<table class="dialog">
        ...
        <jsp:include page="/path/test.jsp" />
</table>
So it seems to me that this include is happening AFTER the inclusions are evaluated.. so the question is.. what can I do to make this work? I've thought about reading the JSP as string and pass it but that's pretty heavy on memory so I want to avoid that.
  • 1. Re: how to insert jsp from javacode into another jsp
    gimbal2 Guru
    Currently Being Moderated
    That's because it is not part of the JSP template, its just content sent to the browser. JSPs are "compiled" into a servlet class after all, so any JSP content needs to be in the JSP template so it is available at "compilation" time.

    What you could do is perhaps take only the page to include from the bean so you make the value of the property variable and not the entire JSP tag.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points