HTTP状态500 -
输入Exception
报告
消息
description服务器遇到内部错误(),导致无法完成此请求。
例外:
javax.servlet.ServletException: Servlet execution threw an exception
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
根本原因:
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)
注意Apache Tomcat / 7.0.14日志中提供了根本原因的完整堆栈跟踪。
Apache Tomcat / 7.0.14
这是我的代码:
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");
}
}
}
答案 0 :(得分:0)
我认为问题与你的代码无关。可能是问题的原因是Jar。 调整类加载顺序,将解决问题。