Forums Register Login

request.getReader()???

+Pie Number of slices to send: Send
hello ranchers,


Please let me know the difference between getting parameter values by using request.getParameter AND request.getReader.

what are the different scenario where we can use request.getReader instead of request.getParameter???


Please Help


Thanks in advance
+Pie Number of slices to send: Send
Is this somthing when we have binary to to send to the server , so this type of data can be deduce by the request.getReader() method ???



Please correct me if i am wrong




Thanks
+Pie Number of slices to send: Send
well I don't know much about this, but in a post request, you can read the request parameters using the getParameter method or you can read the whole contents of the response body using the getReader or the getInputStream methods. Red the documentation of the getParameter method and the getReader method to get some more hints...
+Pie Number of slices to send: Send
my doubt is not yet cleared by reading the documentation of these topics

anyone else please ??
+Pie Number of slices to send: Send
 

what are the different scenario where we can use request.getReader instead of request.getParameter???



request.getReader() retrieves the body of the request as character data using a BufferedReader. Consider a scenario where request came in post method and you want to redirect to some other URL, but you want to pass the same parameters what ever came in the request.

You won't read each parameter using request.getParameter() one by one and construct the query string (for GET) or body (for POST) for redirect. Instead you can read every thing in one shot using request.getReader().

This is one of scenario I can come up with.

thanks
+Pie Number of slices to send: Send
One more doubt ... Is bufferReader return by request.getReader() retrives everything ... what I means to say is querystring etc..??
And can we call the this reader any number of time like we do with request.getParameter()?? Means how I am able to get a value of a particular
parameter.??


Sorry if it seems dumb
+Pie Number of slices to send: Send
Hi,
There is nothing like dumb question.

One more doubt ... Is bufferReader return by request.getReader() retrives everything ... what I means to say is querystring etc..??



Just to clarify when to expect querystring from request - here is what API says about request.getReader() - retrieves the body of the request as character data using a BufferedReader. The request body you get only during HTTP Post. You would get html form parameters as query string only with HTTP Get.

And can we call the this reader any number of time like we do with request.getParameter()?? Means how I am able to get a value of a particular
parameter.??



you can get request.getReader() any number of time. But you can not read the request body content more than once. i.e once you read the content in request body, if you try to read the content again for example like reqeust.getReader().readLine() you would get null.

There is one more interesting thing. You can not use both request.getReader() and request.getParameter() to deal with same request. Which ever you use first, it will steal all the content of request. So the other one will get only null values. For further information about this refer to the topic https://coderanch.com/t/432359/Web-Component-Certification-SCWCD/certification/WhizLab-SCWCD-Mock-Test-Q
So there I was, trapped in the jungle. And at the last minute, I was saved by this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 4542 times.
Similar Threads
how to save an image
HttpServletRequest getReader() - encoding problem
getParameter
regarding POST method.
request.getParameter...not taking Long
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 01:14:17.