• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

request.getReader()???

 
Poonam Agarwal
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Poonam Agarwal
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ankit Garg
Sheriff
Posts: 9521
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Poonam Agarwal
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my doubt is not yet cleared by reading the documentation of these topics

anyone else please ??
 
Sudhaharan Siva
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Poonam Agarwal
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Sudhaharan Siva
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 http://www.coderanch.com/t/432359/Web-Component-Certification-SCWCD/certification/WhizLab-SCWCD-Mock-Test-Q
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic