作为标题,我想在我的jsp项目中使用servlet进行多个上传文件。我正在新项目中对其进行测试,并且没有问题。然后我试图将它实现到我的项目中,它有代码:
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();
}
}
}
}
}
但我总是收到这样的错误:
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.
但我已经在我的 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;
谁能告诉我我的代码有什么问题导致我的上传表单在我的项目中不起作用,但它在新项目中起作用?有时我没有收到错误代码,但我的浏览器出现错误:“连接重置”。它会影响我的项目吗?是什么导致了我的两个问题?
抱歉英语不好。