0

My form has <input type="file"> and other html controls. I am able to upload the file to the server. However when I tried to request.getParameter("phone"); It will output phone = null.

When I remove enctype="multipart/form-data", I am able to get phone. However, upload file does not work.

How can I get phone parameter and upload file work together?

Help will be appreciate and thanks in advance! :)

Below are my codes.

In jsp

<FORM NAME="InputForm" ACTION="servletname" METHOD="POST" enctype="multipart/form-data">
<P><input type="text" name="phone">
<P><input type="file" name="filename">
<P><input type="submit" value="Upload File">
</FORM>

In SERVLET

String phone = request.getParameter("phone");
newbieinjavaversion2
  • 489
  • 5
  • 12
  • 23
  • Please check the answer for this question: http://stackoverflow.com/questions/15105322/multipart-form-data-sending-additional-data which should be similar to your question. – avenet Jan 19 '14 at 13:40

1 Answers1

0

The servlet container is not able to translate form parameters encoded with multipart/form-data. You need to manually decode them or use a third-party library (Apache Commons FileUpload) to extract the form parameters.

Glenn Lane
  • 3,892
  • 17
  • 31