File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Clarrification about  HttpServletRequest Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Clarrification about  HttpServletRequest" Watch "Clarrification about  HttpServletRequest" New topic
Author

Clarrification about HttpServletRequest

Thennam Pandian
Ranch Hand

Joined: Oct 11, 2005
Posts: 163
Hi All,

1. what is the reason to add InputStream as one of the property to HttpServletRequest? give me a practical example?

2. what is the use of that InputStream Object?

thanks in advance...
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

I don't understand.
Thennam Pandian
Ranch Hand

Joined: Oct 11, 2005
Posts: 163
Hi,

we can get the InputStream Object from HttpServletRequest using

getInputStream() method. that means HttpServletRequest interface

implementation class should have one data memeber of type InputStream.


Now My Question is : " what is need to add the InputStream member

to the HttpServletRequest interface implementing class"?

or

what caused the sun to add add the InputStream member

to the HttpServletRequest interface implementing class?
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1280

Hi,

the InputStream is simply used for the purpose described in the API doc.

Marco
Thennam Pandian
Ranch Hand

Joined: Oct 11, 2005
Posts: 163
Hi,

The request body will have only the request parameter.

We can get the all the request parameter using getParameter and

getParameterValues as a String Object.

what is the advantage of reading the request body as a byte over String Object.
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1280

Retrieves the body of the request as binary data...

As the documentation says the method retrieves all the request data at once as "binary data" in contrast to one string per parameter. This may or may not be an advantage depending on what you want to do. In any case it's an advantage if you have for example image data in a POST request uploaded by a user and want to read this definitely binary data.

And don't forget that this method is inherited from ServletRequest. So even though almost all servlets in practice will be based on the HTTP protocol it's absolutely possible to create servlets which are using a complete different communication mechanism where it would be more useful to get any binary request data from such an input stream.

Marco
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Sorry, I have caught up now.

As Marco says, the method comes from ServletRequest and not HttpServletRequest and so may be used by protocols other than HTTP. Having said that, there are times when the data sent in the HttpServletRequest may not be character data, and would need to be read as a binary stream.

The default HTTP encoding is able to parse the request and inflate the data into parameters, but if the request uses an alternate encoding, like a multipart form submission (like a file upload), your servlet will get nothing useful unless you read the InputStream and parse the data yourself, or plug in another API to do it for you.
Thennam Pandian
Ranch Hand

Joined: Oct 11, 2005
Posts: 163
Marco and David , i got it now. thanks a lot...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Clarrification about HttpServletRequest
 
Similar Threads
getting the value of .properties file
HttpServletResponse and HttpServletRequest
How can we read the huge data using request object
OK to read the request body within a filter?
convert from string to inputstream