Skip to Main Content

how to insert jsp from javacode into another jsp

malkyApr 11 2013 — edited Apr 12 2013
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); %>
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" />
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.
Post Details
Added on Apr 11 2013
1 comment