1

I am tring to upload images using image_servlet. the request is passing from product servlet to save_images servlet

 req.getRequestDispatcher("save_images").forward(req, resp);

jsp code

<form action="../save_images" method="POST" enctype="multipart/form-data">
 //img tags in here
</form>

but I got this error

org.apache.commons.fileupload.FileUploadBase$InvalidContentTypeException: the request doesn't contain a multipart/form-data or multipart/mixed stream, content type header is application/x-www-form-urlencoded

I am uploading jpg images. anyone have an idea above this error.

Poorna Senani Gamage
  • 1,246
  • 2
  • 19
  • 30

1 Answers1

1

I believe this question is related to the previous one.

If so, you are making a huge mistake. In the previous question you have entered two <form>s.

But you submit the first <form> which is an application/x-www-form-urlencorded type form, and then parse it to the second servlet using the Requestdispatcher. So the error is pretty obvious here.

Remove the second <form> and add enctype="multipart/form-data" to the first form.

<div class=container>
    <form action="../save_product" method="POST" enctype="multipart/form-data">
        <button type="submit" id="formsave2"></button>
         <div class="panel">
         </div>
         <div class="panel">
             // img tags in here
         </div>
    </form>
</div>

Remember, the form you are submitting should have the enctype mentioned.

Roshana Pitigala
  • 8,437
  • 8
  • 49
  • 80
  • Actually I can not use single form tag to this stuff. if I use single form tag, the close form tag cannot sync with the open form tag.(
    not sync). that why I using two forms.
    – Poorna Senani Gamage Jun 03 '18 at 11:50
  • Then make it sync. You can even open the form tag after the body (`
    `) tag and close it before closing the body tag (`
    `).
    – Roshana Pitigala Jun 04 '18 at 04:36