2

我正在编写此处概述的简单上传 JSP 和 Servlet 教程:

上传教程

我已经对系统进行了编码并且我的网页已经完成,但是在运行应用程序时我遇到了错误。当我单击上传按钮时,例如:

    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 页面也如下所示:

错误图片

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

4

2 回答 2

3

您忘记/错过了添加 apache 公共文件上传 jar

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

检查你的lib/maven jar结构。

于 2013-08-06T14:02:19.070 回答
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。

于 2015-02-05T08:11:16.630 回答