0

is there a possiblity to upload a file from html forms without using multipart/form-data? I'm using Servlets 2.5 so I can't use getPart method and I still want to use getParameter method to get values from fields.

2

3 Answers 3

1

Use apache commons fileupload to handle mpe requests, like everyone else.

Sign up to request clarification or add additional context in comments.

2 Comments

but when I use apache commons I have to use multipart/form-data which doesn't allow me to use getParameter method
Why not use Servlet 3.0 API?
0

The multipart/form-data encoding type is a fundamental part of the HTML file upload mechanism - see for instance the RFC where it was first standardised, particularly this section headed "File transfer with ENCTYPE=x-www-form-urlencoded".

While there are other methods of uploading files now available (e.g. backed by Flash widgets) none of these can allow you to submit part of the form in normal x-www-form-encoded format but also attach uploaded files.

Perhaps you could write a wrapper object which wraps an API which supports multipart/form-data and implements the getParameter method you want on top of it for non-file fields.

Comments

0

You have to use the enctype form attribute to upload files.

And since you're not using Servlet 3.0, you have to create your own filter if you want to keep using the request.getParameter() calls to get data from the input fields. You can find full examples here and here.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.