Apache returns this error while trying to upload a file (I only kept the first lines of the stacktrace and root causes):
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.p开发者_开发知识库arseRequest(Lorg/apache/commons/fileupload/RequestContext;)Ljava/util/List;
org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:126)
Here is my code:
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);
}
}
I dont get it, it looks like it can't find the parseRequest() method, but the ServletFileUpload instanciation works fine, so it seems like the package is there but...
Any idea? All suggestions help appreciated! :)
This is indeed a sign of classpath pollution. You have different versions of the commons fileupload JAR file spreading over the classpath. You need to clean up the classpath by removing or replacing the older-versioned ones. In case of a JSP/Servlet webapplication, the default paths which are covered by the classpath are usually the Webapp/WEB-INF/lib
, Webapp/WEB-INF/classes
, Appserver/lib
and the JRE/lib
.
That said, the stacktrace also indicates that you wrote raw Java code inside JSP files using the old fashioned scriptlets. I would strongly recommend not to do so, but just to use a real Java class (in this case a Servlet) to handle the file upload.
noSuchMethod error could be caused by a mismatch between the version of the jar you compiled against and the jar in the runtime classpath. This is something to double-check.
精彩评论