This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "problem with  multipart/form-data" Watch "problem with  multipart/form-data" New topic
Author

problem with multipart/form-data

Loveen Jain
Ranch Hand

Joined: Jan 24, 2004
Posts: 35
[That is, given the form:
<FORM ACTION="/servlet/FooServlet"
ENCTYPE="multipart/form-data"
METHOD=POST>

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>

</FORM>

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

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

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
Sheriff

Joined: Dec 11, 2004
Posts: 13410

http://jakarta.apache.org/commons/fileupload

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
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Right,
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: http://aspose.com/file-tools
 
subject: problem with multipart/form-data
 
Similar Threads
How can I read parameters from a multipart/form-data upload form?
HTTP POST maximum data size?
upload servlet
More problems with file uploads
Servlets, HTML forms, multipart/form-data