异常:java.lang.ClassNotFoundException:运行Servlet时的javax.servlet.http.HttpServletRequest

时间:2013-08-06 14:00:21

标签: java java-ee tomcat servlets apache-commons

我正在编写一个简单的上传JSP和Servlet教程:

Upload Tutorial

我有系统编码和我的网页已完成但我在运行应用程序时遇到错误。当我点击上传按钮时,例如:

    SEVERE: Servlet.service() for servlet [UploadServlet] in context with path [/Test] threw exception [Servlet execution threw an exception] with root cause
java.lang.ClassNotFoundException: javax.servlet.http.HttpServletRequest
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at org.apache.commons.fileupload.servlet.ServletFileUpload.isMultipartContent(ServletFileUpload.java:68)
    at com.dell.UploadServlet.doPost(UploadServlet.java:45)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:724)

我正在执导的tomcat页面看起来如下:

Error Picture

有人知道我做错了什么吗?感谢

2 个答案:

答案 0 :(得分:3)

您忘记/错过了添加apache common fileupload jar

 at org.apache.commons.fileupload.servlet.ServletFileUpload.
                     isMultipartContent(ServletFileUpload.java:68)

检查lib/maven jar结构。

答案 1 :(得分:0)

我有一个类似的例外 - 不同的情况,但在我的情况下,servlet-api.jar显然应该是$CATALINA_HOME/lib/,但是我安装了针对不同的servlet-api.jar编译的jar。产生了这个例外:

java.lang.NoClassDefFoundError: javax/servlet/http/HttpServlet

快速修复是使用最初编译servlet的servlet-api.jar,虽然在生产中我建议重新编译你的servlet而不是替换tomcat的核心jar。