• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting the query string in included and forwared servlet or page

 
Bindu Lakhanpal
Ranch Hand
Posts: 171
Flex Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For include:getQueryString() returns the original query string or null (but never the new query string).
The attribute(javax.servlet.include.query_string) returns the new query string or null( but never the original query string).

For forward:
getQueryString() returns the original and if available then new query String.
The attribute(javax.servlet.forward.query_string) returns the original or null( but never the new one).

By original query string i mean the one passed with initial request.By new one i mean the query string which is sent to included( or forwarded page).

Am i right?Please tell me if i am wrong.
I tested it but it is still so confusing.
Why they made them so different?
 
Chinmaya Chowdary
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bindu. What You said is correct.
Why they made them so different?
I think, the included thing(wether jsp or servlet) don't require to display 'original query string' by using the attribute(javax.servlet.include.query_string) type. It will display the new query string(the one we set through <jsp:param > incase of jsp or by providing query string like ?paramOne="Bindu" incase of Servlet, that makes sense.)
 
Bindu Lakhanpal
Ranch Hand
Posts: 171
Flex Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am still confused about whether this behaviour is according to what specs say.

What I understood is
1)In case of include, the methods( request.getXXX()) return the values of the source.So to get the values in target we use the request attributes(javax.servlet.include.XXX).

2) In case of forward, the methods( request.getXXX()) return the values of the target.So to get the values in source we use the request attributes(javax.servlet.forward.XXX).

Now consider that original request for a page source.jsp is like


and source.jsp contains


Now using method request.getQueryString() in the target.jsp returns foo=original (as expected)
And using request.getAttribute(javax.servlet.include.query_string) returns null (as expected)


But if source.jsp contains


using method request.getQueryString() in target.jsp returns foo=original ( i expected to get null)
-------------------(A)
using request.getAttribute(javax.servlet.forward.query_string) returns foo=original (as expected)

I tried to get answer in specs.But could not find .Should it be null in (A) according to specifications?

I tested it using tomcat 6.0.18.
 
Chinmaya Chowdary
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bindu.
using method request.getQueryString() in target.jsp returns foo=original ( i expected to get null)-------------------(A)
using request.getAttribute(javax.servlet.forward.query_string) returns foo=original (as expected)

Forwarded page must have all details.
 
Bindu Lakhanpal
Ranch Hand
Posts: 171
Flex Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Chinmaya,
Thanks.
So, i should just remember it as it is.
But in spec i could not get any clear information regarding this.




 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic