Apache在尝试上传文件时返回此错误(我只保留了stacktrace的第一行和根本原因):
HTTP Status 500 - type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception org.apache.jasper.JasperException: Exception in JSP: /upload.jsp:40 37: 38: try { 39: 40: items = upload.parseRequest(request); 41: } catch (FileUploadException e) { 42: out.println(e); 43: } Stacktrace: org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:451) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) root cause javax.servlet.ServletException: org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(Lorg/apache/commons/fileupload/RequestContext;)Ljava/util/List; root cause java.lang.NoSuchMethodError: org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(Lorg/apache/commons/fileupload/RequestContext;)Ljava/util/List; org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:126)
这是我的代码:
if(ServletFileUpload.isMultipartContent(request)){ FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); List items = null; try { items = upload.parseRequest(request); } catch (FileUploadException e) { out.println(e); } }
我不明白,它似乎找不到parseRequest()方法,但是ServletFileUpload实例工作正常,所以似乎包在那里但…
任何的想法?所有建议均对您有所帮助!:)
这确实是类路径污染的迹象。您有不同版本的commons fileupload JAR文件分布在类路径中。您需要通过删除或替换旧版本的类来清理类路径。在一个JSP / Servlet的web应用的情况下,这是由类路径所覆盖的默认路径通常是Webapp/WEB-INF/lib,Webapp/WEB- INF/classes,Appserver/lib和JRE/lib。
Webapp/WEB-INF/lib
Webapp/WEB- INF/classes
Appserver/lib
JRE/lib