We have a jsp landing page that has a menu and a horizontal line.
Under the horizontal line we want to display the selected menu option
which is another jsp, without pasting the main page code into the
other file. The jsp is initially called from a @WebServlet using request.getRequestDispatcher().forward(), and I want to pass
variables into the nested jsp. I use request.setAttribute(), or session.setAttribute() to set variables, and they resolve in the main
page jsp but not the nested jsp with any method I could find so far
to dynamically display the nested page.
A few ideas:
1) Just (mis)use session to pass the info.
2) Use dynamic include instead of static include and pass
info as query parameter.
3) Switch to a master page capable technology like
JSF facelets - I seem to recall that there exist
a Java web framework that supports master pages via
a taglib, but I cannot remember the name.
Arne
I found that you can pass values one at a time from one page file to another using import params, but if the page does something, like call a form .submit(), those values get lost.ArneI've never used Facelets, from what I can tell that may be a better architecture for that sort of thing but would require a full rewrite.
I couldn't figure a solution that passes everything as is, where you can reference ${var} in the parent JSP and ${var} in the nested JSP, but I did find this option seems to work:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:import url="${pagetoload}">
<c:param name="passvar" value="${vartopass}"/>
</c:import>
Then in the nested JSP, have to reference variables like ${param.passvar}
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 304 |
Nodes: | 16 (0 / 16) |
Uptime: | 03:01:37 |
Calls: | 6,826 |
Calls today: | 6 |
Files: | 12,340 |
D/L today: |
1 files (2,541K bytes) |
Messages: | 5,407,635 |