You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Robert Shields <rs...@star.net.uk> on 2004/07/15 13:16:21 UTC

servlet request.getInputStream() always returns an empty stream

Hi,

request.getInputStream() always gives me an empty stream, even though
request.getContentLength() is non-zero (18)!



public class TestServlet extends HttpServlet {
   ResourceBundle rb = ResourceBundle.getBundle("LocalStrings");
   
   public void doGet(HttpServletRequest request,
                     HttpServletResponse response)
       throws IOException, ServletException
   {
	InputStream inputStream = request.getInputStream();
		
	
	int length = request.getContentLength(); // 18

	String contentType= request.getContentType();
      // application/x-www-form-urlencoded
	
	int bytesAvailable = inputStream.available(); // 0
		
	byte[] buf = new byte[1024];
	int bytesread;
	
	// bytesread is always -1
	while((bytesread = inputStream.read(buf)) != -1)
	{
		// do stuff
	}
   }

   public void doPost(HttpServletRequest request,
                     HttpServletResponse response)
       throws IOException, ServletException
   {
       doGet(request, response);
   }
}


So bytesAvailable () is always 0, and inputStream.read(buf) immediately
returns -1.

Could there be something wrong with the configuration of Tomcat? If so,
what could it be?
I'm using Tomcat 5.0.25.

Thanks in advance,
Rob


This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
_____________________________________________________________________

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org