Hi Bill
Thanks for your response.
I've tried with a servlet too, but even without calling
request.getParameter the stream is still empty:
public class TestServlet extends HttpServlet {
ResourceBundle rb = ResourceBundle.getBundle("LocalStrings");
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
int length = request.getContentLength(); // 18
String contentType= request.getContentType();
// application/x-www-form-urlencoded
InputStream inputStream = request.getInputStream();
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);
}
}
This should work, right?
I'm starting to think something is wrong with my Tomcat!
Regards,
Rob
-----Original Message-----
From: news [mailto:[EMAIL PROTECTED] On Behalf Of Bill Siggelkow
Sent: 15 July 2004 14:16
To: [EMAIL PROTECTED]
Subject: Re: calling request.getInputStream() within Action
Robert, I found the following link that discusses this:
http://archives.java.sun.com/cgi-bin/wa?A2=ind0106&L=jsp-interest&F=&S=&
P=49196
It sounds like you are correct -- if request.getParameter() has been
called you cannot get the input stream -- have you considered using a
Servlet instead?
Robert Shields wrote:
> Hi Struts Users
>
> I'm trying to get the InputStream to read the binary contents of the
> request within an Action's execute method. E.g.
>
>
>
> public ActionForward execute(
> ActionMapping mapping,
> ActionForm form,
> HttpServletRequest request,
> HttpServletResponse response)
> throws IOException, ServletException {
>
> InputStream inputStream = request.getInputStream();
>
> // bytesAvailable is always 0
> int bytesAvailable = inputStream.available();
>
> int bytesRead;
> byte[] buf = new byte[1024];
> while((bytesRead = inputStream.read(buf)) != -1)
> {
> // do stuff
> }
> }
>
> So bytesAvailable is always 0, and inputStream.read(buf) immediately
> returns -1.
>
> I have heard that calling request.getParamter() before trying to
access
> the input stream can affect accessing the input stream. I believe
struts
> calls request.getParamter (it must do to populate the form bean).
>
> My question is, how can I get access to the entire binary contents of
> the HTTP body?
>
> I'm using Tomcat 5.0.25 BTW
>
> TIA
> 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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
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
_____________________________________________________________________
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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]