problem with file upload in jsp

This question already has an answer here:

  • How to upload files to server using JSP/Servlet? 12 answers

  • You need to drop the commons-fileupload.jar and commons-io.jar files in /WEB-INF/lib folder of your webapp project. This folder becomes ultimately part of webapp's runtime classpath. Note that in a bit decent IDE like Eclipse/Netbeans/IntelliJ, you do not need to fiddle with buildpath properties afterwards. The IDE is perfectly aware that libraries in /WEB-INF/lib are to be taken part of the runtime classpath, so it adds that to the build path automagically.


    No, the problem is that (Tomcat?) can't find "org.apache.commons.fileupload.servlet.ServletFileUpload".

    Make sure you've installed the correct .jar, make sure you've configured your server and/or web app correctly.

    You haven't provided any details about exactly how you're running "servlets" (Tomcat? Jboss? Something else entirely?), so we can't guide you any further than "The problem is server configuration on your part!"

    ADDENDUM: Copy the .jar file to your Tomcat lib directory, restart Tomcat, and try again. That should resolve the "class not found" error.


    Apart from adding those libs to WEB-INFO/lib , I had to change the imports from my servlet to use those certain libs, from:

    import org.apache.tomcat.util.http.fileupload.FileItem;
    import org.apache.tomcat.util.http.fileupload.FileUploadException;
    import org.apache.tomcat.util.http.fileupload.disk.DiskFileItemFactory;
    import org.apache.tomcat.util.http.fileupload.servlet.ServletFileUpload;
    

    to

    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;
    
    链接地址: http://www.djcxy.com/p/46234.html

    上一篇: 实例化servlet类时出错

    下一篇: 在jsp中上传文件的问题