By default, available() method of java.io.InputStream always returns zero. Not sure, whether implementing subclass of this class now overrides that and returns valid data.
Long back (probably in Tomcat 3 or 4) we tried that and failed because of the same reason. As far as I remember, available() method never returned outside 0.
Joined: Nov 29, 2005
So can by any chance I not get a inputstream of the body of the request ? By reading the javadoc for getInputStream method in the HTTPServeltRequest I think that this should give me the inputstream of the body of the request.But not happening in this way.I suspect a bug or am i doing some mistake.
But if I pass the same date as parameter , then i am able to get that using request.getParameter()..why is that so ?
You can not call both getInputStream and getParameter from the same request.
The container will parse the request once. As soon as you call getParameter, the input stream gets parsed and it's no longer available. Likewise, once you call getInputStream, it is no longer possible to get parameters with getParameter.
[KLUNK] [ September 20, 2006: Message edited by: Ben Souther ]
Can I not get a inputStream of the body of the request using this?
People do this all the time. How exactly are you trying to do it?
NOTE: If you do any getParameter calls at all, anywhere in the request process before you try to get the stream, the request stream will have been read by the servlet engine and will not be usable. Bill
I am not trying to use getParameter and getInputStream together.When my code contained only getInputStream then I get a stream whith no data/bytes in that.(Using tcpmon I have verified that client is sending the data in the body of the request properly.)
But when I send the date from client as a POST request and data as parameter ,I am able to get that in servlet using getParameter.
Joined: Aug 12, 2002
Rahul, As per Servlet API (do not remember starting from when), getParameter of HttpServletRequest works for both query string parameters (for GET) and request body data (for POST). But, getInputStream() works only for request body data (i.e. for POST).