Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #39739 > unrolled thread

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

Started by"e.d.pro...@gmail.com" <e.d.programmer@gmail.com>
First post2022-03-17 13:20 -0700
Last post2022-03-23 11:40 -0700
Articles 4 — 2 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  Is there a good way to wrap a jsp in a jsp? "e.d.pro...@gmail.com" <e.d.programmer@gmail.com> - 2022-03-17 13:20 -0700
    Re: Is there a good way to wrap a jsp in a jsp? Arne Vajhøj <arne@vajhoej.dk> - 2022-03-17 19:52 -0400
      Re: Is there a good way to wrap a jsp in a jsp? "e.d.pro...@gmail.com" <e.d.programmer@gmail.com> - 2022-03-18 09:19 -0700
        Re: Is there a good way to wrap a jsp in a jsp? "e.d.pro...@gmail.com" <e.d.programmer@gmail.com> - 2022-03-23 11:40 -0700

#39739 — Is there a good way to wrap a jsp in a jsp?

From"e.d.pro...@gmail.com" <e.d.programmer@gmail.com>
Date2022-03-17 13:20 -0700
SubjectIs there a good way to wrap a jsp in a jsp?
Message-ID<52c29918-5654-47c5-acd4-b5fe74d43037n@googlegroups.com>
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.

[toc] | [next] | [standalone]


#39740

FromArne Vajhøj <arne@vajhoej.dk>
Date2022-03-17 19:52 -0400
Message-ID<6233c9b5$0$697$14726298@news.sunsite.dk>
In reply to#39739
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

[toc] | [prev] | [next] | [standalone]


#39741

From"e.d.pro...@gmail.com" <e.d.programmer@gmail.com>
Date2022-03-18 09:19 -0700
Message-ID<dd1436df-4ce2-48c4-b702-53ae67e4b429n@googlegroups.com>
In reply to#39740
> 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}

[toc] | [prev] | [next] | [standalone]


#39743

From"e.d.pro...@gmail.com" <e.d.programmer@gmail.com>
Date2022-03-23 11:40 -0700
Message-ID<a608f687-beb1-4a5a-ab56-82708aef321fn@googlegroups.com>
In reply to#39741
> > 
> > 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.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web