This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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
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).]