hibernateservletsapache-commons-fileuploadrequestdispatcher

Get error from file uploading


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.


Solution

  • 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.