0

I want to upload an image to DB. i use java servlet for this purpose. but i got an exception

HTTP Status 500 - Unable to process parts as no multi-part configuration has been provided

my jsp page:

<form action="uploadservlet" method="post"
              enctype="multipart/form-data">
           <input type="file" name="photo" size="50"/>
            <br />
            <input type="submit" value="Upload File" />
        </form>

and my servlet post method is

public void doPost(HttpServletRequest request, 
                   HttpServletResponse response)
                  throws ServletException, java.io.IOException {
        InputStream inputStream = null; // input stream of the upload file

            // obtains the upload file part in this multipart request
            Part filePart = request.getPart("photo");
            if (filePart != null) {
                // prints out some information for debugging
                System.out.println(filePart.getName());
                System.out.println(filePart.getSize());
                System.out.println(filePart.getContentType());

                // obtains input stream of the upload file
                inputStream = filePart.getInputStream();
            }
       }
Ajmal Muhammad
  • 685
  • 7
  • 25
  • 1
    Please the the answer of @BalusC in the question I mentioned above. You might have missed to annotate your servlet (you did not show the relevant code). – home Jul 30 '15 at 05:33

1 Answers1

0

The servlet needs to be annotated with @MultipartConfig (i.e. javax.servlet.annotation.MultipartConfig). The @MultipartConfig annotation allows the servlet to handle requests made using the multipart/form-data MIME type. Another option is to mark the DispatcherServlet with a "multipart-config" section in web.xml

You can also have a look at commons-fileupload that provides greater flexibility.

sravtej
  • 63
  • 6