简体   繁体   English

在Tomcat5上使用fileupload的异常

[英]Exception using fileupload on Tomcat5

I'm trying to develop and uploader servlet, and for that I'm using fileupload librery from Apache. 我正在尝试开发和上传servlet,为此,我正在使用来自Apache的fileupload librery。 I'm running my servlet on: Server Version: Apache Tomcat/5.5.36 Servlet Version: 2.4 JSP Version: 2.0 我在以下服务器上运行我的servlet:服务器版本:Apache Tomcat / 5.5.36 Servlet版本:2.4 JSP版本:2.0

I'm getting the next exception and I have no idea what do more: 我遇到下一个异常,我不知道该怎么做:

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)
photoUploader.processRequest(photoUploader.java:48)
photoUploader.doPost(photoUploader.java:87)
javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

It seems to be a trouble with the imports, but I'm not sure. 进口似乎有点麻烦,但我不确定。

This is the code I'm using for doing that: 这是我用于执行此操作的代码:

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;

public class photoUploader extends HttpServlet {

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");

        final String RUTA_LOCAL_APP = getServletContext().getRealPath("/");
        out.println("<!DOCTYPE html>");
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet photoUploader</title>");            
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Servlet photoUploader at " + request.getContextPath() + "</h1>");
            out.println("<h5>Versiones del Servlet: M->" + getServletContext().getMajorVersion() + 
                        "| m->" + getServletContext().getMinorVersion() + "</h5>");
            out.println("<h5>Adjunta MultipartContent?: " + ServletFileUpload.isMultipartContent(request) + "</h5>");
            }
        catch(Exception e)
        {
            out.println("<h3>Excepción: </h3>" + e.getMessage());
        }
        finally{
            out.println("</body>");
            out.println("</html>");
        }
    }

When I check if isMultipartContent out.println("<h5>Adjunta MultipartContent?: " + ServletFileUpload.isMultipartContent(request) + "</h5>"); 当我检查isMultipartContent out.println("<h5>Adjunta MultipartContent?: " + ServletFileUpload.isMultipartContent(request) + "</h5>"); is when I get the error. 是当我得到错误。

Im sure I've got *.jar in right place: 我确定我在正确的位置放置了* .jar:

Webapp Content:
├───CSS
│       Stuff
│
├───JS
│   │   jquery-1.11.2.js
│   │
│   └───jquery-ui
│       │   Stuff
│       │
│       ├───external
│       │   └───Stuff
│       │
│       └───images
│               Stuff
│
├───META-INF
│       MANIFEST.MF
│
├───static
│   │   Stuff
│   │
│   └───imagenes
│           Stuff
│
└───WEB-INF
    │   web.xml
    │
    ├───classes
    │       photoUploader.class
    │       
    │
    └───lib
            commons-fileupload-1.3.1.jar
            commons-io-2.4.jar
            GXClassR.jar
            iText.jar
            mysql-connector-java-3.1.13-bin.jar
            poi.jar

Id like to know if: 我想知道是否:

  • there's any way to check that imported lib are in the right place in runtime. 有任何方法可以检查导入的库在运行时是否位于正确的位置。

  • is there any trouble with version of my server (Apache Tomcat/5.5.36 Servlet Version: 2.4 JSP Version: 2.0) Some known issue I haven't read. 我的服务器版本是否有问题(Apache Tomcat / 5.5.36 Servlet版本:2.4 JSP版本:2.0)我尚未阅读一些已知问题。

  • the idea is to use only *.class (with servlet definition inside WEB-INF/classes) to work together with the other servlets I have. 这个想法是仅使用* .class(在WEB-INF / classes中具有servlet定义)与我拥有的其他servlet一起工作。 I tell you this because if I deploy the war using Tomcat Manager it works without any trouble, but inside my own App it fails. 我告诉你这是因为,如果我使用Tomcat Manager部署战争,它可以正常工作,但是在我自己的应用程序中会失败。 May be it's not importing libs as it should. 可能是它没有按原样导入库。

Any help/idea is welcome, I've tried all solutions proposed on StackOverflow and no one worked for me, so I'm asking again. 欢迎任何帮助/想法,我已经尝试了所有关于StackOverflow的解决方案,但没有人为我工作,所以我再次询问。

Thanks 谢谢

Finally I got it. 终于我明白了。 I work with Genexus, and inside GXClassR.jar (library used by Genexus) there was another instance of the same *.class (aparently older and out of date). 我使用Genexus,在GXClassR.jar (Genexus使用的库)内部,存在另一个* .class实例(显然较旧且过时)。 I deleted it and leaved only the new one and it worked. 我删除了它,只留下了一个新的,它起作用了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM