Does request.getParameter() still work when uploading files with Servlet 3.0?

file-upload, java, jsp, servlets, tomcat

Solution

I tried to simply call request.getParameter("description"), and it seems to work fine.

Indeed, this is specified as such in the Servlet 3.0 spec, but this did not work in earlier versions of Glassfish until recently, even though it's the reference implementation. This has been reported as Glassfish issue 16740 and has been fixed in 3.1.2, more than 2 years after the first 3.0 release.

Problem

I just read this great answer from BalusC about how to upload files with the 3.0 Servlet API. My question is about the use of `request.getParameter()` for common fields. For example, if my form looks like this : ``` <form action="/upload" method="post" enctype="multipart/form-data"> <fieldset> <label for="description">File description:</label> <input type="text" id="description" name="description" value="" /> <label for="uploadedFile">File:</label> <input type="file" id="uploadedFile" name="uploadedFile" /> <input type="submit" value="Send" /> </fieldset> </form> ``` Following what BalusC explained, I should manipulate the InputStream returned by `part.getInputStream()` to get the content of the description field. Why is that ? I tried to simply call `request.getParameter("description")`, and it seems to work fine. I use Tomcat 7.0.20. Thanks for your help.

Original source

Related problems