File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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

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,

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


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
Piotr Nowicki
Ranch Hand

Joined: Jul 13, 2010
Posts: 610

Hi Nidhi!

Sure - just take a look at the spec:

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:


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.

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!
I agree. Here's the link:
subject: Attribute "javax.servlet.forward.query_string" ?
It's not a secret anymore!