• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

request.getReader()???

 
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my doubt is not yet cleared by reading the documentation of these topics

anyone else please ??
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 https://coderanch.com/t/432359/Web-Component-Certification-SCWCD/certification/WhizLab-SCWCD-Mock-Test-Q
 
Shiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic