As is usual, part of the answer lies in the javadoc. MultipartRequest
has methods getParameter(String), getParameterValue(String) and
getParameterNames(). The javadoc does not explicitly state that these
should be called instead of the HttpServletRequest methods, but the
javadoc does say, "This class emulates the interface of
HttpServletRequest, making it familiar to use."  A simple experiment
could have revealed whether they return the same thing as the
HttpServletRequest methods (which they do). So simply create
MultipartRequest in the entry servlet and call its getParameter(String)
method.

The reason your problem occurs is that calling getParameter(String) of
the HttpServletRequest class causes the class to read from the stream.
Once the stream is opened, the MultipartRequest class gets an
IOException when it tries to read from the stream because all the data
from the stream has been exhausted. You will find this even if you don't
use MultipartRequest. On many servers, if you open and read from the
stream using HttpServletRequest, then calls to getParameter(String) will
fail, and vice versa.

Kevin Mukhar

Matthias Carlsson wrote:
>
> Hi,
>
>         I'm using the class MultipartRequest from servlets.com to upload files
> in my web application. I've noticed a strange behaviour when using
> this class.
>
> Apparently, you CAN NOT call getParameter() from the request-object before
> creating an instance of MultipartRequest. Doing so will result in this
> exception:
>
> java.io.IOException: Corrupt form data: premature ending        at
> com.oreilly.servlet.MultipartRequest.readRequest(MultipartRequest.java:356)
> at com.oreilly.servlet.MultipartRequest.<init>(MultipartRequest.java:149)
> ...
> ...
>
> This is a problem for me, because I use an "entry-servlet" which gets all
> request. This servlet reads a parameter to determine what to do. So,
> in my doGet()- and doPost()-methods (doPost actually just calls doGet) I
> read this parameter. This worked fine until I started to write my uploading
> -routines.

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to