0
votes

HTTP Status 500 -

type Exception report

Message

description The server encountered an internal error () that prevented it from fulfilling this request.

Exception:

javax.servlet.ServletException: Servlet execution threw an exception
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)

Root cause:

java.lang.NoSuchMethodError: org.apache.commons.fileupload.FileUploadBase.isMultipartContent(Lorg/apache/commons/fileupload/RequestContext;)Z
org.apache.commons.fileupload.servlet.ServletFileUpload.isMultipartContent(ServletFileUpload.java:71)
WindsofChange.User_FileEncrypt.doPost(User_FileEncrypt.java:50)
javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)

note The full stack trace of the root cause is available in the Apache Tomcat/7.0.14 logs.

Apache Tomcat/7.0.14

Here is my Code:

public class ServletDemo extends HttpServlet {
private static final byte[] initialization_vector = { 22, 33, 11, 44, 55, 99, 66, 77 };
File encryptedPath, uploadedFile;
String fileName;



@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    boolean isMultipart = ServletFileUpload.isMultipartContent(request);  
     response.setContentType("text/html");  
      PrintWriter out = response.getWriter();  
    if (isMultipart) {  
       // Create a factory for disk-based file items  
       FileItemFactory factory = new DiskFileItemFactory();  
       // Create a new file upload handler  
       ServletFileUpload upload = new ServletFileUpload(factory);  
      try {  
         // Parse the request  
         List /* FileItem */ items = upload.parseRequest(request);  
        Iterator iterator = items.iterator();  
        while (iterator.hasNext()) {  
          FileItem item = (FileItem) iterator.next();
          //filesize=item.getSize(); get filesize in bytes
          if (!item.isFormField())  
           {  
            fileName = item.getName();
            String root = getServletContext().getRealPath("/");
            File path = new File(root + "/uploads");  
            //if uploads folder not exists create
            if (!path.exists())  
             {  
              boolean status = path.mkdirs();  
             }  
            uploadedFile = new File(path + "/" + fileName);
            encryptedPath = new File(path + "/encrypted" + fileName);
            out.println(uploadedFile.getAbsolutePath()); 
            try{
             if(fileName!="")  
            item.write(uploadedFile);  
             else  
               out.println("file not found");  
            }catch(Exception e){}
             out.println("File Uploaded Successfully....:-)");  
          }  
           else  
           {  
             String abc = item.getString();  
           }

        }
        }catch(Exception e){e.printStackTrace();}

       }  
     else  
     {  
       out.println("Not Multipart");  
     }
  } 

}
1
earlier i run the same code it works. but now its thorows the above exception. is there anything i want to make change. - rit tech
what code where is it ? - Yehia Awad
You need to copy commons-fileupload jar to your WEB-INF/lib/ directory and then restart the server. - Gaurav Sharma
@яша i have updated my code - rit tech
@GauravSharma I have already done that thing ya. earlier it works well. but now its throws exception. nothing i have changed. - rit tech

1 Answers

0
votes

I think the problem have nothing to do with your code.May be the reason of the problem is Jar. Adjust the class loading sequence,would be solve the problem。