File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes problems with forms + multipart/form + servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "problems with forms + multipart/form + servlets" Watch "problems with forms + multipart/form + servlets" New topic

problems with forms + multipart/form + servlets

Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
Hi guys.
I have a jsp form with different things (checkboxes, input type, drop down menus, etc), and I also have a file option where the user can select a file from his/her computer.
The request goes to a servlet. After a while I noticed that when I type
String category = request.getParameter("category")
all the values returned are NULL
I also noticed that if I take out the encode type in the form (multipart/form), The values are not null anymore.
What's wrong?? I need to have the encode type in the form because I'm uploading that image in the server.
Any suggestions?

I'm not going to be a Rock Star. I'm going to be a LEGEND! --Freddie Mercury
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

The way data is organised when the encoding type is multipart/form is completely different to the regular encoding.
The problem is that the default decoding can't handle it and therefore returns nothing. You need to get something like the O'Reilly cos package (com.oreilly.servlet) to parse the data to extract the form data including files.
I agree. Here's the link:
subject: problems with forms + multipart/form + servlets
It's not a secret anymore!