my dog learned polymorphism*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes javax.servlet.include. . . Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "javax.servlet.include. . ." Watch "javax.servlet.include. . ." New topic
Author

javax.servlet.include. . .

Stein Vom
Ranch Hand

Joined: Jul 10, 2005
Posts: 78
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

Joined: Mar 22, 2007
Posts: 329

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 ]

SCJP 1.4 (88%) - SCJP 5.0 Upgrade (93%) - SCWCD 1.4 (97%) - SCBCD 5.0 (98%)
Stein Vom
Ranch Hand

Joined: Jul 10, 2005
Posts: 78
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

Joined: Mar 22, 2007
Posts: 329

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

Joined: Jul 10, 2005
Posts: 78
Thanks for the reply again.
 
wood burning stoves
 
subject: javax.servlet.include. . .
 
Similar Threads
welcome-file tag in DD
Need clarification for jsp:include.
linking jsp pages in a liferay portlet
jsp page redirection
Navigating to another page...