• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

javax.servlet.include. . .

 
Stein Vom
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • 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
 
Sergio Tridente
Ranch Hand
Posts: 329
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • 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
  • 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
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks for the reply again.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic