Reputation: 563
I'm trying to develop and uploader servlet, and for that I'm using fileupload librery from Apache. I'm running my servlet on: Server Version: Apache Tomcat/5.5.36 Servlet Version: 2.4 JSP Version: 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>");
is when I get the error.
Im sure I've got *.jar in right place:
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.
the idea is to use only *.class (with servlet definition inside WEB-INF/classes) to work together with the other servlets I have. 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. 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.
Thanks
Upvotes: 0
Views: 193
Reputation: 563
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). I deleted it and leaved only the new one and it worked.
Upvotes: 2