This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Servlets and the fly likes HttpServletRequest's getQueryString() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "HttpServletRequest Watch "HttpServletRequest New topic
Author

HttpServletRequest's getQueryString()

Bob Moranski
Ranch Hand

Joined: Nov 22, 2000
Posts: 177
Hi, can someone help me on this one? What does HttpServletRequest's getQueryString() return? I read the Servlet API and am confused by it.
yadav prabha
Greenhorn

Joined: Dec 25, 2000
Posts: 5
Originally posted by Bob Moranski:
Hi, can someone help me on this one? What does HttpServletRequest's getQueryString() return? I read the Servlet API and am confused by it.


hello buddy
this return the data that u have passed form one form to another thru ur forms post method which the defauult..u can see in the url some question marks and some variables..
hope this clears ur doubts
bye
yadav

Thanks in Advance<BR>yadav
maha anna
Ranch Hand

Joined: Jan 31, 2000
Posts: 1467
Bob,
getQueryString() returns all the html form's data in this format as a loooooong string.
name1=value1&name2=value2&name3=value3........nameN=valueN
For example
firstName=Frank&lastName=Carver&Title=Sheriff&Favorate=Servlet&Favorate=JSP&Favorate=XML
Have you noticed this above line? Favaorate field may be a multiple choice pull down field in the html file and the user has selected more than one items. So in 'queryString' we get 1...N Favorate=*** patterns.
So, if we want to get the whole form's sent data as a string we ask for request.getQueryString() method. Usually we don't do this parsing on our own. There are some nice servlet APIs available to do this task for us like getParameter("paramName") or getParamValues("paramName") (in case of multiple values for one param) getParamNames() etc.
One situation where this may be useful is , when one form send's its data to Servlet1 and Servlet1 does some processing and forwards this whole request data along with some more new data to another resource. I did encounter this situation once, but not often.
Also note that this getQueryString() will work for both GET and POST form's METHOD types. In case of GET all data in the url AFTER the 'questionMark' '?' will be returned.
In case of GET you can see in the browser's url www.webappcabaret.com/maha/servlet/servlet1?firstName=FranklastName=Carver....
So the getQueryString() will return the string starting from firstName=Frank upto end.
Also note that, it is good idea to use POST method instead of GET, since the form's data are not exposed in browser'd URL. Also we can't send larger form data in GET METHOD type since the the total length of the URL is limited to 2K. (I think so)
Ex. <form name = "form1" action="/servlet/servlet1" METHOD="POST">
OR
<form name = "form1" action="/servlet/servlet1" METHOD="GET">
regds
maha anna
[This message has been edited by maha anna (edited December 25, 2000).]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HttpServletRequest's getQueryString()
 
Similar Threads
Problem getting values passed from aspx to jsp
getQueryString()
getAttribute()
RequestDispatcher.forward() and PageContext.forward()
Request.ServerVariables()