eclipse java.lang.ClassNotFoundException: HttpServletRequest
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27663406/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java.lang.ClassNotFoundException: HttpServletRequest
提问by Rizwan Awan
I was using Tomcat v8.0.15 on Eclipse Luna, it was working fine. Later, I installed Netbeans; which automatically installed another instance of Tomcat. I deleted one of them. In the result, tomcat stopped working on Eclipse; whenever I try to start tomcat, this error appears:
我在 Eclipse Luna 上使用 Tomcat v8.0.15,它运行良好。后来,我安装了Netbeans;它自动安装了另一个Tomcat实例。我删除了其中之一。结果,tomcat 停止在 Eclipse 上工作;每当我尝试启动 tomcat 时,都会出现此错误:
Caused by: java.lang.NoClassDefFoundError: HttpServletRequest
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2693)
at java.lang.Class.getDeclaredMethods(Class.java:1967)
at org.apache.catalina.util.Introspection.getDeclaredMethods(Introspection.java:127)
at org.apache.catalina.startup.WebAnnotationSet.loadMethodsAnnotation(WebAnnotationSet.java:273)
at org.apache.catalina.startup.WebAnnotationSet.loadApplicationServletAnnotations(WebAnnotationSet.java:133)
at org.apache.catalina.startup.WebAnnotationSet.loadApplicationAnnotations(WebAnnotationSet.java:65)
at org.apache.catalina.startup.ContextConfig.applicationAnnotationsConfig(ContextConfig.java:334)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:774)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:305)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5095)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 6 more
Caused by: java.lang.ClassNotFoundException: HttpServletRequest
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1295)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1147)
... 20 more
回答by Cristhian Amaya
So it happened to me just now and here is how I solved it: In the web.xml file I attempted to modify the servlet-name in my "servlet" tag from "DefaultServlet" to "DispatcherServlet", however the servlet-name in my "servlet-mapping" tag remained "DefaultServlet". All I had to do is to set the SAME servlet name (so "DispatcherServlet") for both "servlet" and "servlet-mapping" in their respective "servlet-name" tags. Once done it worked as a charm.
所以它刚刚发生在我身上,这是我解决它的方法:在 web.xml 文件中,我试图将“servlet”标记中的 servlet-name 从“DefaultServlet”修改为“DispatcherServlet”,但是 servlet-name 在我的“servlet-mapping”标签仍然是“DefaultServlet”。我所要做的就是在各自的“servlet-name”标签中为“servlet”和“servlet-mapping”设置相同的servlet名称(即“DispatcherServlet”)。一旦完成,它就像一个魅力。