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

problem with multipart/form-data

Loveen Jain
Ranch Hand

Joined: Jan 24, 2004
Posts: 35
[That is, given the form:
<FORM ACTION="/servlet/FooServlet"

What is your name? <INPUT TYPE=TEXT NAME='submitter'><br>

What file are you sending? <INPUT TYPE=FILE NAME=secretDocument><br>

<input type="submit" value=Submit><br>


I cannot read the submitter using request.getParameter("submitter") (it returns null). ]

javax.servlet.HttpServletRequest.getParameter(String) returns null when the ContentType is multipart/form-data
Paulo Pontes

Joined: Dec 06, 2004
Posts: 20
the standard classes supplied by sun does not suport multipart/form-data (file transfer forms)
give a look at jakarta commons and you will find a set of classes to make file transfer servlets.
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

Very easy to use

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Loveen Jain
Ranch Hand

Joined: Jan 24, 2004
Posts: 35
my problem is not to upload the file....its how to get the value of other fields such as textbox input from a form where one field is for file upload.
request.getparameter returns null.
and if i dont use multipart/form-data then i wont b able to upload the file..
so please tell me the solution to get the value of text fields in servlet.
as request.getparameter() doesn't work. !! i am uploading a file from the same form. so i ll have to use multipart/form-data.....
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

Use the commons/fileupload tool that I showed you. It provides methods for retrieving your parameters. getParameter doesn't work with mulit-part forms.
I agree. Here's the link:
subject: problem with multipart/form-data
It's not a secret anymore!