• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

QueryString revisited - information

 
Ranch Hand
Posts: 558
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 329
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
All that thinking. Doesn't it hurt? What do you think about this tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic