• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

including jsp within jsp

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my1.jsp includes my2.jsp. I need to include my2.jsp if certain parameters are true(which i need to check in my1.jsp) which are passed from a servlet to my2.jsp and then need to pass to my1.jsp. How can i check those variables in my1.jsp.
class MyServlet
{
// passing the value of myvar to my2.jsp
req.setAttribute("myvar",myvar);
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(my2.jsp);
}
my2.jsp
// retieving the value of myvar in my2.jsp
String myvar = (String)request.getAttribute("myvar");
my1.jsp
if(myvar) // how can i pass the value of myvar to this jsp
<%@ include file="my2.jsp" %>
thanks for the help
arpit
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you include (or forward) jsp2 then they share the same request and response objects. ie jsp2 should be able to read the Attribute as well.
Dave.
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think, if I'm reading it right, you can't do this the way you've coded.

You are setting a value in jsp2, which you use from jsp1, to determine if you're supposed to include jsp2 or not?

You should pass it to jsp1 first, then *if* you need to include jsp2, jsp2 can be dynamically included, and it will automatically have access to the same request object (and thus, the value you are checking) as jsp1.

Did that make sense?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic