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


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "forward + queryString" Watch "forward + queryString" New topic
Author

forward + queryString

Adolfo Eloy
Ranch Hand

Joined: Mar 21, 2009
Posts: 146

When solving the Exercise 12 from chapter 5 of Head First Servlets & JSP, the statement below was said to be wrong.
"The Servlet to which a request is forwarded may access the original query string by calling getQueryString() on the HttpServletRequest."
It's said in the book that this is incorrect because this method returns the query string on the URL pattern from the RequestDispatcher.

When trying by coding an example I've seen that the statement above is true and not wrong as said the book.
I've created two Servlets called SourceServlet.java and DestineServlet.java.
The SourceServlet is called with a GET method from a link from any html page as
<a href="SourceServlet?name=adscript">Link</a>

When checking the query string data at SourceServlet, those data is there as expected.
So I've coded a dispatching to DestineServlet to check there for URL parameters and queryString invocation method.
The result was as I've expecting: when invoking the getQueryString method, I've got the value name=adscript.

So I'd like to know if I'm interpreting this exercise wrong, or it's an error at the answer provided by HF Servlets & JSP.

Note: I'm reading the second edition. At the first edition, the statement was said to be true.

Code example:





Thanks!!


Adolfo Eloy
Software Developer
OCPJP 6
Niiraj Patel
Ranch Hand

Joined: Sep 17, 2011
Posts: 47
I have altered your Servlets little to get rid..

modify query string when you forward.



Print both original param. of SourceServlet and forwarded request's parameter.



Now, you will able to see two different queries..
1.query string Original:name=adscript
2.query string forwarded:name=newQueryParam

Conclusion : forward/include methods first store original query string value in attribute and set new query string to new request object.




 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: forward + queryString