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

getQueryString()

 
Duran Harris
Ranch Hand
Posts: 608
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone please explain the difference between getQueryString() and getAttribute("javax.servlet.forward.query_string")...
please...
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
javax.servlet.forward.query_string contains the same result as getQueryString, but it's only set for servlets which has been forwarded by another servlet. (using a RequestDispatcher not retrieved via getNamedDispatcher).
 
Duran Harris
Ranch Hand
Posts: 608
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK no problem
 
Santhi Bharath
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Duran Harris wrote:Can someone please explain the difference between getQueryString() and getAttribute("javax.servlet.forward.query_string")...
please...


Duran Harris wrote:Can someone please explain the difference between getQueryString() and getAttribute("javax.servlet.forward.query_string")...
please...


If I am correct there are five request attributes to get information about the path

-- javax.servlet.forward.context_path or javax.servlet.include.context_path
-- javax.servlet.forward.servlet_path or javax.servlet.include.servlet_path
-- javax.servlet.forward.path_info or javax.servlet.include.path_info
-- javax.servlet.forward.request_uri or javax.servlet.include.request_uri
-- javax.servlet.forward.query_string or javax.servlet.include.query_string

for both include and forward

But the difference is if you forward the request these attributes has to be set according to new path. If it is include request these values has to be original reqeust values

getQueryString() -- always gives you the current quesry string .
 
Duran Harris
Ranch Hand
Posts: 608
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK thanks,that clears it up nicely then!
But what is path info?
 
Santhi Bharath
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But what is path info?


let suppose

/catalog -- context of web application
/servlet/* -- is the servlet path mentioned in DD

then for a request /catalog/servlet/pathinfo.html

pathinfo.html -- pathinfo
 
Duran Harris
Ranch Hand
Posts: 608
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay.Thank you
 
Rob Spoor
Sheriff
Pie
Posts: 20751
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christophe Verré wrote:javax.servlet.forward.query_string contains the same result as getQueryString

Not necessarily.
With forwarding it is possible to add some more parameters to the query. These then show up in getQueryString(), but javax.servlet.forward.query_string contains the original query string - without the added parameters.

With javax.servlet.include.query_string it's the other way around - the attribute has the added parameters.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I was not very clear. I was referring to SRV.8.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:
javax.servlet.forward.request_uri
javax.servlet.forward.context_path
javax.servlet.forward.servlet_path
javax.servlet.forward.path_info
javax.servlet.forward.query_string

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.
 
Duran Harris
Ranch Hand
Posts: 608
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's not very intuitive....that:

javax.servlet.forward.query_string doesn't have the parameters
whilst javax.servlet.include.query_string does....

What does this say about the include and forward methods??
 
Duran Harris
Ranch Hand
Posts: 608
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's not very intuitive....that:

javax.servlet.forward.query_string doesn't have the parameters
whilst javax.servlet.include.query_string does....

What does this say about the include and forward methods??
 
Duran Harris
Ranch Hand
Posts: 608
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Isn't that all a query string is...parameters?
 
Rob Spoor
Sheriff
Pie
Posts: 20751
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes it is.

When you are forwarding, you are overwriting these values, so the javax.servlet.forward attributes contain the old values (for the forwarding servlet). Old (from forwarding servlet) from attributes, new (from forwarded servlet) from HttpServletRequest.

When you are including, you are not overwriting these values, so the javax.servlet.include attributes contain the new values (for the included servlet). Old (from including servlet) from HttpServletRequest, new (from included servlet) from attributes.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic