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

multipart/form-data inputs

Stephen ODonnell

Joined: Sep 07, 2004
Posts: 19
Hi all,

I am trying to upload a file using a jsp page but I am having a problem with multipart/form-data. It doesn't seem to find some of my input parameters!!

When I try the above code 'mydesc' can be found in the http request but not 'name' and 'filename' and I swap the code around (see below) I can see 'name' and 'filename' but not 'mydesc'.

Does anyone know what is wrong?
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

How are you trying to retrieve the parameters?

request.getParameter() doesn't work with multipart forms. You need to use the methods provided by the upload libraries you are using.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Stephen ODonnell

Joined: Sep 07, 2004
Posts: 19
Hi Ben,

Thanks for your reply. This is the code i'm using get the parameter from the request:

But when I print out the line passed into getDispositionInfo(), I either get

form-data; name="name"; filename="C:\reports\Monthly.rpt"[B]


[B]form-data; name="mydesc"

depending on which order they are in, in the Jsp.
Is there a handy any of logging to file all the contents of the request?

Dan Novik
Ranch Hand

Joined: Jan 26, 2005
Posts: 39
Check out this for example:
Stephen ODonnell

Joined: Sep 07, 2004
Posts: 19
Hi all,

Thanks for your help. I've used tag-lib method. But i've run into a strange problem. I am doing the upload to tomcat as follows:

I get the contextPath which is /myreports however the report gets saved as number and not the proper file name.

When I hardcode the path every thing works fine. Ideally I want to save the reports in contextPath/Reports i.e myreports/Reports

Has anyone had this problem?? What am I doing wrong?
I agree. Here's the link:
subject: multipart/form-data inputs
It's not a secret anymore!