aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes request.getReader()??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "request.getReader()???" Watch "request.getReader()???" New topic
Author

request.getReader()???

Poonam Agarwal
Ranch Hand

Joined: May 12, 2008
Posts: 323
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


Thanks <br />Poonam Agarwal SCWCD 86%
Poonam Agarwal
Ranch Hand

Joined: May 12, 2008
Posts: 323
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

Joined: Aug 03, 2008
Posts: 9304
    
  17

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...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Poonam Agarwal
Ranch Hand

Joined: May 12, 2008
Posts: 323
my doubt is not yet cleared by reading the documentation of these topics

anyone else please ??
Sudhaharan Siva
Greenhorn

Joined: Jan 14, 2009
Posts: 7
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

Joined: May 12, 2008
Posts: 323
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

Joined: Jan 14, 2009
Posts: 7
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: request.getReader()???