问题描述
Apache 在尝试上传文件时返回此错误(我只保留了堆栈跟踪的第一行和根本原因):
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.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 实例化工作正常,所以看起来包在那里但是...
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! :)
推荐答案
这确实是类路径污染的标志.您有分布在类路径上的不同版本的公共文件上传 JAR 文件.您需要通过删除或替换旧版本的来清理类路径.对于 JSP/Servlet web 应用程序,类路径覆盖的默认路径通常是 Webapp/WEB-INF/lib
、Webapp/WEB-INF/classes
、Appserver/lib
和 JRE/lib
.
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
.
也就是说,堆栈跟踪还表明您使用 老式的scriptlets.我强烈建议不要这样做,而只是使用真正的 Java 类(在本例中为 Servlet)来处理文件上传.
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.
这篇关于阿帕奇公地 ->文件上传 ->解析请求()错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!