wood burning stoves 2.0*
The moose likes Servlets and the fly likes Forwarding ServletInputStream Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Forwarding ServletInputStream" Watch "Forwarding ServletInputStream" New topic

Forwarding ServletInputStream

Kannan Plr

Joined: Nov 04, 2003
Posts: 4
Hi all,
I searched the forum to fix the problem which iam facing on ServletInputStream.
I want to read the servletinputstream.
But the method
servletinputstream.available() is returning me "0" bytes.
request.getContentLength() is returning me "268" bytes.
my requirement is to read the servletinputstream and forward that stream to an application residing in the different server through URL connection. But iam failing in read() itself.
Here is my code
Iam submitting the following form to an JSP (ReadForm.jsp)
<form action="ReadForm.jsp" method="post" enctype="multipart/form-data">
<input type=text name='uname'><br>
<input type=password name='pword'><br>
<input type=hidden name='pagename' value="WPS/ReadForm"><br>
<input type=file>
<input type=submit><br>
ReadForm.jsp contains following code
InputStream sis = request.getInputStream();
int noofBytes = sis.available();
out.println("no of bytes" + noofBytes);
out.println("<br>contentlength " +request.getContentLength())

The output is
no of bytes 0
contentlength 389

please tell me where iam going wrong?

Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Someone pointed out to me that available() is unreliable for raw streams, maybe for servlet input stream as well. It may return 0 if its current buffer is exhausted, but that doesn't mean it can't read another buffer later. The OReilly multipart reader http://www.servlets.com/cos/index.html uses the reader ... it might serve as an example of doing it.

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
I agree. Here's the link: http://aspose.com/file-tools
subject: Forwarding ServletInputStream
Similar Threads
Servlet becomming slow
Problem in uploading file in jsp
Upload files from a HTML <input type="file"> with a servlet
problem with setContentType() method
Array Index Out Of Bounds