• Is there a good way to wrap a jsp in a jsp?

    From e.d.programmer@gmail.com@21:1/5 to All on Thu Mar 17 13:20:34 2022
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From =?UTF-8?Q?Arne_Vajh=c3=b8j?=@21:1/5 to e.d.pro...@gmail.com on Thu Mar 17 19:52:20 2022
    On 3/17/2022 4:20 PM, e.d.pro...@gmail.com wrote:
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From e.d.programmer@gmail.com@21:1/5 to All on Fri Mar 18 09:19:12 2022
    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'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}

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From e.d.programmer@gmail.com@21:1/5 to All on Wed Mar 23 11:40:55 2022

    Arne
    I'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}
    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.
    So to set up constants available to every page as ${variable}, I use request.getServletContext().setAttribute() in a javax.servlet.Filter, which can be in a common module referenced from multiple war modules.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)