Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

QueryString revisited - information

 
Srinivasan thoyyeti
Ranch Hand
Posts: 558
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers,

I would like to share following observation regarding query strings.
(please neglect this if you already know this).

How to obtain "Original" query string in a forwarded servlet. and
How getQueryString() behaves in forwarded servlet.

1. request URL used at browser

http://localhost:9081/mappingTest/one?name=srinivas

2. In First Servlet (mapped to "/one" in webapp) .

getQueryString() --> name=srinivas

//forwarding to SecondServlet
RequestDispatcher dispatcher = request.getRequestDispatcher("/two?name=moses");
dispatcher.forward(request,response);

3. In Second Servlet (mapped to "/two" in webapp)

getQueryString() --> name=moses
//to get original query string submitted.
request.getAttribute("javax.servlet.forward.query_string");



Hope the flow is clear.
Any query please post.
[ August 07, 2007: Message edited by: Srinivasan thoyyeti ]
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nice obserrvation Srini!

It means, the original request parameter is saved as attribute to the
request scope.


Thanks,
[ August 07, 2007: Message edited by: Chandra Bhatt ]
 
Michael Ku
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you know if this is required by the spec or something that was implemented by the particular server implementation that you are using?
 
Srinivasan thoyyeti
Ranch Hand
Posts: 558
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its there in the servlet specs.
container has to create a request scope attribute when forward happens "javax.servlet.forward.query_string". sothat original query string avail to forwarded servlet.

Have a look at RequestDispatcher Section.
Thanks for the appreciation guys.
 
Sergio Tridente
Ranch Hand
Posts: 329
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nice explanation Srinivasan. Now try the same but instead of forwarding to another servlet do an include. What happens now?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic