0

Possible Duplicate:
How to upload files in JSP/Servlet?

I'm having some strange issue with file uploads using servlets.

I read that I need to add the following attribute to my form: enctype="multipart/form-data"

The thing is, when I'm adding this, all the POST data don't reach the HttpServletRequest object (the one with all the data collected from the form). When I'm removing the "enctype" attribute from my form, everything seems to work fine and I can see all the data the user entered in the form.

What am I doing wrong? How can I successfully combine between "regular" form data and a file upload?

Community
  • 1
  • 1
Shai
  • 1,093
  • 4
  • 13
  • 20
  • 1
    possible duplicate of [How to upload files in JSP/Servlet?](http://stackoverflow.com/questions/2422468/how-to-upload-files-in-jsp-servlet/2424824#2424824) and http://stackoverflow.com/questions/4840476/how-to-submit-jsp-page-with-encoding-multipart-form-data/4840512#4840512 – BalusC Aug 20 '11 at 14:49

2 Answers2

0

Use a web framework (Stripes, Spring MVC, etc.) supporting file uploads, or use the apache commons FileUpload to handle them. For a reason that I can't understand, the servlet API (prior to 3.0) doesn't support them natively.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
0

I highly recommend just reading up on ApacheFileUpload http://commons.apache.org/fileupload/

Honestly, it has great documentation and is really easy to install. Alternatively if you're running Tomcat 7 (I'm guessing you're not) it has the MultipartForm data there. The commons API works well, has a lot of options, and allows you to access the streams directly without caching to a file if you need it.

Daniel B. Chapman
  • 4,647
  • 32
  • 42