1

As a title, I want to doing multiple upload files in my jsp project using servlet. I'm testing it in new project, and it's done without problems. Then I'm trying to implement it to my project which has code:

boolean isMultipart = ServletFileUpload.isMultipartContent(request);
        if (!isMultipart) {
        } else {
            FileItemFactory factory = new DiskFileItemFactory();
            ServletFileUpload upload = new ServletFileUpload(factory);
            List items = null;
            try {
                items = upload.parseRequest(request);
            } catch (FileUploadException e) {
                e.printStackTrace();
            }
            Iterator itr = items.iterator();
            while (itr.hasNext()) {
                FileItem item = (FileItem) itr.next();
                if (item.isFormField()) {
                } else {
                    try {
                        String itemName = item.getName();;
                        File savedFile = new File("D://uploadedFiles");
                        item.write(savedFile);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        }

    }

But I always getting error like this:

HTTP Status 500 -

type Exception report

message

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

exception

javax.servlet.ServletException: PWC1392: Error instantiating servlet class servlet.ManagementProdukServlet

root cause

java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileUploadException

root cause

java.lang.ClassNotFoundException: org.apache.commons.fileupload.FileUploadException

note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 3.1.2 logs.

But I have import this at my servlet:

import controller.Produk;
import dao.DataAksesAdmin;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;

Could anybody tell me what's wrong with my code that made my upload form doesn't work in my project, but it's work in new project? And sometimes I don't get the error code but I have error: "Connection reset" on my browser. Is it affect my project? And what cause the problem with that 2 my problems?

sorry for bad English.

Cross Vander
  • 2,077
  • 2
  • 19
  • 33

2 Answers2

2

reading this link, is very well explained. Servlet 3.0 don“t work fine with apache fileupload 1.3. How to upload files to server using JSP/Servlet?

Community
  • 1
  • 1
Alrio
  • 102
  • 1
  • 9
1

Even though you are importing in the source file, the jar should be in classpath. If you are running from ide, make sure you do clean build, and once there are no errors deploy and start the project. If you are deploying as a war make sure your war includes the required jar file.

prashanth
  • 445
  • 5
  • 14