JSP中的NoClassDefFoundError

时间:2015-03-07 17:19:46

标签: java jsp

我在ServletException中得到一个NoClassDefFoundError,在第二行中:

List items;
items = servlet_up.parseRequest(request);

我一直在寻找它,并且从Why am I getting a NoClassDefFoundError in Java?我认为我已经理解了这种情况,但不是解决方案。

how to fix NoClassDefFoundError in java Alvaro说我们可以导入缺少的库来修复它,但是从那以后:

1.-我不知道哪个库适合我(也许是servlet-api.jar?)

2.-这是一个JSP而不是Java类(我的意思是,我不编译它,所以我不知道它使用的是哪个jar)

3.-我应该把罐子放在哪里?在JSP App的./lib/文件夹中?

就是这样,我真的不知道如何继续。

提前谢谢!

更新:这不是List类的问题,因为问题出在已经使用过List的第二行。

此外,我还有以下导入:

<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<%@ page import="org.apache.commons.io.*" %>
<%@ page import="org.apache.commons.fileupload.*" %>
<%@ page import="org.apache.commons.fileupload.disk.*" %>
<%@ page import="org.apache.commons.fileupload.servlet.*" %>

最后,我在运行时获得的是(我将删除一些代码注释的行以缩短代码):

type Informe de Excepción
mensaje
descripción El servidor encontró un error interno () que hizo que no pudiera rellenar este requerimiento.
excepción

org.apache.jasper.JasperException: Ha sucedido una excepción al procesar la página JSP /uploadFile.jsp en línea 39

37:   ServletFileUpload servlet_up = new ServletFileUpload(file_factory);
39:   List items = servlet_up.parseRequest(request);

Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:521)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:412)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

causa raíz

javax.servlet.ServletException: java.lang.NoClassDefFoundError: org/apache/commons/io/IOUtils
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:865)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:794)
org.apache.jsp.uploadFile_jsp._jspService(uploadFile_jsp.java:137)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

causa raíz

java.lang.NoClassDefFoundError: org/apache/commons/io/IOUtils
org.apache.commons.fileupload.util.Streams.copy(Streams.java:123)
org.apache.commons.fileupload.util.Streams.copy(Streams.java:70)
org.apache.commons.fileupload.MultipartStream.readBodyData(MultipartStream.java:593)
org.apache.commons.fileupload.MultipartStream.discardBodyData(MultipartStream.java:617)
org.apache.commons.fileupload.MultipartStream.skipPreamble(MultipartStream.java:634)
org.apache.commons.fileupload.FileUploadBase$FileItemIteratorImpl.findNextItem(FileUploadBase.java:1023)
org.apache.commons.fileupload.FileUploadBase$FileItemIteratorImpl.<init>(FileUploadBase.java:1003)
org.apache.commons.fileupload.FileUploadBase.getItemIterator(FileUploadBase.java:310)
org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:334)
org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:115)
org.apache.jsp.uploadFile_jsp._jspService(uploadFile_jsp.java:97)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

1 个答案:

答案 0 :(得分:0)

从您的异常堆栈跟踪中,很明显您在类路径中缺少org/apache/commons/io/IOUtils类。所以在你的WEB-INF / lib目录中添加commons-io-2.4.jar(不一定是2.4,它可以是任何其他版本)。

您可以在Maven Repository here

中找到所有JAR