0

I am uploading an image file using commons fileupload, using post method. Image uploading is successful but when I try to access any other fields of the form using request.getParameter("field_name"); method I get null values of all corresponding fields as result of which I am getting Exceptions of all kind. Here is the code of my form:

<form id="add-book" name="add-book" class="add-book" method="post" action="ServletImageUpload" enctype="multipart/form-data">
        <table>
        <tr>
          <td>field1</td>
          <td><input type="text" name="isbn" id="isbn" /></td>
         </tr>
         <tr>
           <td>Upload image</td>
           <td><input type="file" name="upload"  /></td>//image upload field
         </tr>

       <!--rest of the form fields -->
 </form>

So is the problem with the request.getParameter(); method? Why am I not able to get the values of the parameter?

Nix
  • 57,072
  • 29
  • 149
  • 198
Vishal Anand
  • 581
  • 3
  • 10
  • 22

1 Answers1

1

I guess you can't use request.getParameter() when form is multipart. You can use Apache Commons Fileupload which provides API to parse a multipart request, and iterate through the parts of it individually.

kaysush
  • 4,797
  • 3
  • 27
  • 47