0

This is my upload form:

form id='picform' action='UploadImage' method='post' enctype='multipart/form-data'>
   <input type='file' name='Photo' />
<input type='submit' />
</form>

and my UploadServlet:

import java.io.*;
import java.sql.*;
import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;

@WebServlet("/uploadServlet")
@MultipartConfig(maxFileSize = 16177215) 
public class UploadImage extends HttpServlet {

    protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    InputStream inputStream = null;
    Part filePart = request.getPart("Photo");
    if (filePart != null) {
        System.out.println(filePart.getName());
        System.out.println(filePart.getSize());
        System.out.println(filePart.getContentType());

        inputStream = filePart.getInputStream();            
    }

String message = null; 
    try{

    //loading drivers for mysql
    Class.forName("com.mysql.jdbc.Driver");

      Connection  con=DriverManager.getConnection
                 ("jdbc:mysql://195.243.249.131:3306/****","****","****");

    PreparedStatement ps=con.prepareStatement
              ("update users set Photo=? where email=?");
HttpSession session=request.getSession(false);
String email=(String)session.getAttribute("email");

    ps.setString(1, email);
    int i=ps.executeUpdate();

        if (inputStream != null) {
            // fetches input stream of the upload file for the blob column
            ps.setBlob(3, inputStream);
        }

        int row = ps.executeUpdate();
        if (row > 0) {
            message = "Image is uploaded successfully into the Database";
        }        
    }
          catch(Exception se)
    {
        se.printStackTrace();
    }   
   }
  }

but i get this exception when trying to upload a file:

java.lang.AbstractMethodError: org.apache.catalina.connector.RequestFacade.getPart(Ljava/lang/String;)Ljavax/servlet/http/Part; UploadImage.doPost(UploadImage.java:21) javax.servlet.http.HttpServlet.service(HttpServlet.java:644) javax.servlet.http.HttpServlet.service(HttpServlet.java:725)

ArK
  • 20,698
  • 67
  • 109
  • 136
Adurna0
  • 1
  • 3

0 Answers0