There is a better solution. The jsp-tags aren't very flexible, and you can always do the same with pure Java. if you don't know how to do it in Java, just look at the corresponding java file that is the compiled jsp-file, placed in "work" directory of apache. There you can see how jasper translated your jsp-directives into java-code.
My problem was similar to yours. Here is my solution:
What for example if you want to have different menus on your webpages and the jsp-file for the menu (along with different parameters if needed) should be passed in runtime? Let's say I call "http://myServer/fullPage.jsp?topMenu=myTop.jsp"
here is fullPage.jsp:
-
<%!
-
private boolean includeIfExisting(String pageName, PageContext pageContext)
-
throws Exception
-
{
-
HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
-
String url = request.getParameter(pageName);
-
if (url != null)
-
{
-
if (Log.isDebug()) Log.debug("before including " + pageName + " =" + url);
-
pageContext.include(url);
-
if (Log.isDebug()) Log.debug("after including " + pageName + " =" + url);
-
-
return true;
-
}
-
return false;
-
}
-
%>
-
...
-
<div id=menu>
-
<%
-
includeIfExisting("topMenu", pageContext);
-
%>
-
</div>
-
...