aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Attribute Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Attribute "javax.servlet.forward.query_string" ?" Watch "Attribute "javax.servlet.forward.query_string" ?" New topic
Author

Attribute "javax.servlet.forward.query_string" ?

Nidhi Sar
Ranch Hand

Joined: Oct 19, 2009
Posts: 252

I came across this attribute ("javax.servlet.forward.query_string") in Niko's mock exam. Is this some kind of standard attribute that stores some value?

Here is the question:


Consider doGet() of a valid servlet with url pattern /source,
response.sendRedirect("target");

and doGet() of another valid servlet with url pattern /target.

response.getWriter().println(request.getAttribute("javax.servlet.forward.query_string"));

What is the output when invoking http://localhost:9999/exam/source?user=nikos&pass=12345? (1 correct answer)

a. user=nikos&pass=12345
b. null


I have never seen "javax.servlet.forward.query_string", and couldn't locate it in online API. Anyone know where I should look to see it's decription?


"A problem well stated is a problem half solved.” - Charles F. Kettering
SCJP 6, OCPJWCD
Piotr Nowicki
Ranch Hand

Joined: Jul 13, 2010
Posts: 610

Hi Nidhi!

Sure - just take a look at the spec: http://jcp.org/aboutJava/communityprocess/final/jsr315/index.html

Section 9.4.2, pp. 92 - 93.


9.4.2 Forwarded Request Parameters

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 following request attributes must be set:

javax.servlet.forward.request_uri
javax.servlet.forward.context_path
javax.servlet.forward.servlet_path
javax.servlet.forward.path_info
javax.servlet.forward.query_string


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. These attributes are accessible from the forwarded servlet via the getAttribute method on the request object. Note that these attributes must always reflect the information in the original request even under the situation that multiple forwards and subsequent includes are called.

If the forwarded servlet was obtained by using the getNamedDispatcher method, these attributes must not be set.


Cheers!


OCP Java SE 6 Programmer, OCM Java SE 6 Developer, OCE Java EE 6 JSPSD, OCE Java EE 6 EJBD, OCE Java EE 6 JPAD, Spring 3.0 Core Professional.
Nidhi Sar
Ranch Hand

Joined: Oct 19, 2009
Posts: 252

Hi Pedro, I had this spec downloaded in my computer. Just didn't realize this info would be in there. Thanks for your answer!
 
jQuery in Action, 2nd edition
 
subject: Attribute "javax.servlet.forward.query_string" ?