• 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

scope of jsp:param

 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Consider the following code:

main JSP:

<jsp: include page="/jsp/includeTest.jsp">
<jsp: param name="test" value="ABC" />
</jsp: include>
in main page: ${ param.test }


/jsp/includeTest.jsp:

in included page: ${ param.test }
<jsp: include page="/jsp/includeTest2.jsp"/>


/jsp/includeTest2.jsp:

in second included page: ${ param.test }


This will output
in included page: ABC
in second included page: ABC
in main page:



There's something not clear about this, or even incorrect, in HFSJ. The Book says that the <jsp: param> will create a request parameter, that is visible for all the components in the webapp that is part of the request. But as the above code shows, it is only available for the duration of the include/forward.

Credits go to Charles Lyon, as I got the concept from his Garner Press mock exam. (Code is not copied from it literally.)
[ August 18, 2008: Message edited by: Jan Sterk ]
 
Author
Posts: 836
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Request parameters introduced by <jsp:param> only survive between the opening <jsp:include> and the closing </jsp:include> in which they are declared. It is supposed to be a temporary override for an included page (and its subsequently included pages) only.

Think of the container as using an HttpServletRequestWrapper and overriding the getParameter methods to explicitly return the new value. The wrapper is then passed as the request argument to the RequestDispatcher used to perform the include. Using the wrapper means it doesn't alter the original request parameter map, just override a few selected name/value pairs for the duration of the include. When the RequestDispatcher include returns, the wrapper is binned, so we're back to where we started. There's a similar example (except it overrides request headers not query parameters) on pages 140-141 of my book. <jsp:param /> is on p.333 where I also state "it is (temporarily) overridden".
[ August 18, 2008: Message edited by: Charles Lyons ]
reply
    Bookmark Topic Watch Topic
  • New Topic