• 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

javax.servlet.include. . .

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the use of attributes . .
javax.servlet.include.query_string
javax.servlet.forward.query_string
etc

when we can get the attribute's values directly
For example:

In page1.jsp:

<jsp:include page="page2.jsp" />
---------------------------------
And in page2.jsp

<%=request.getQueryString()%>
<%=request.getAttribute("javax.servlet.include.query_string")%>
---------------------------------
When I run the page1.jsp like this:

..page1.jsp?abc=xyz


It gives:

abc=xyz null
 
Ranch Hand
Posts: 329
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is a big difference between the javax.servlet.include.* and the javax.servlet.forward.* attributes.

Section SRV.8.3.1 of the spec speaks about the javax.servlet.include.* attributes in these terms:


Except for servlets obtained by using the getNamedDispatcher method, a servlet that has been invoked by another servlet using the include method of RequestDispatcher has access to the path by which it was invoked.
[...]their values must be equal to the request URI, context path, servlet path, path info, and query string of the included servlet, respectively. If the request is subsequently included, these attributes are replaced for that include.



Whereas in section SRV.8.4.2, it states the following for the javax.servlet.forward.* attributes:


Except for servlets obtained by using the getNamedDispatcher method, a servlet that has been invoked by another servlet using the forward method of RequestDispatcher has access to the path of the original request.
[...]
The values of these attributes must be equal to the return values of the HttpServletRequest methods getRequestURI, getContextPath, getServletPath,
getPathInfo, getQueryString respectively, invoked on the request object passed to the first servlet object in the call chain that received the request from the client.



I didn't know either that it worked that way. I supposed that both forward and include's attributes were giving the original request parameters. But it seems that both behave differently.
[ April 30, 2007: Message edited by: Sergio Tridente ]
 
Stein Vom
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Sergio for the reply!

I think i got it, these attributes are usefull in the cases where we do include/forward from an Servlet. Correct me if i'm wrong.
 
Sergio Tridente
Ranch Hand
Posts: 329
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, you are right. They are usuful in the case we include/forward one servlet from another. (Just to make it clearer, when I say servlet I mean both the servlets generated from java classes implementing Servlet and/or HttpServlet or the servlets created from JSP pages.)
 
Stein Vom
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply again.
 
reply
    Bookmark Topic Watch Topic
  • New Topic