Apache Commons->文件上传-> parseRequest()错误 [英] Apache commons -> File Upload -> parseRequest() error

查看:111
本文介绍了Apache Commons->文件上传-> parseRequest()错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Apache尝试上传文件时返回此错误(我只保留了stacktrace的第一行和根本原因):

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! :)

推荐答案

这确实是类路径污染的标志.您有不同版本的commons fileupload JAR文件分布在类路径中.您需要通过删除或替换旧版本的类来清理类路径.对于JSP/Servlet Web应用程序,类路径覆盖的默认路径通常是Webapp/WEB-INF/libWebapp/WEB-INF/classesAppserver/libJRE/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.

也就是说,stacktrace还表明您使用老式的 scriptlet .我强烈建议您不要这样做,而只是使用真正的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.

这篇关于Apache Commons->文件上传-> parseRequest()错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆