java Servlet.service() 抛出 ClassCastException

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12814008/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 10:20:17  来源:igfitidea点击:

Servlet.service() throws ClassCastException

javaservletstomcat6classcastexceptionjdk1.6

提问by Rishabh

I have a java web application. I have set up this new project and getting the following exception when I run a jsp,

我有一个 Java Web 应用程序。我已经设置了这个新项目,并在运行 jsp 时出现以下异常,

Oct 10, 2012 3:01:49 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.ClassCastException: org.apache.catalina.util.DefaultAnnotationProcessor cannot be cast to org.apache.AnnotationProcessor
    at org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:151)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:340)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Thread.java:619)
Oct 10, 2012 3:01:57 AM org.apache.catalina.loader.WebappClassLoader modified
INFO:     Additional JARs have been added : 'activation-1.1.jar'
Oct 10, 2012 3:01:57 AM org.apache.catalina.core.StandardContext reload
INFO: Reloading this Context has started
Oct 10, 2012 3:01:57 AM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
SEVERE: The web application [/AutoUpgrade] registered the JBDC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
Oct 10, 2012 3:01:57 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/AutoUpgrade] appears to have started a thread named [Timer-0] but has failed to stop it. This is very likely to create a memory leak.

I have tried clean and building the project many times, getting the latest service-api.jar, my lib is very extensive and I cannot figure out whether there is any inconsistencies between any jar that is causing this error. I am running the project on Apache Tomcat 6 on jdk 1.6 (my project needs to run on 1.6). I have tried googling this exception, but didnt get any post relevant to my problem. The relevant questions on stackoverflow talk about NullPointerException.

我已经多次尝试清理和构建项目,获取最新的 service-api.jar,我的库非常广泛,我无法弄清楚导致此错误的任何 jar 之间是否存在任何不一致。我在 jdk 1.6 上的 Apache Tomcat 6 上运行该项目(我的项目需要在 1.6 上运行)。我试过谷歌搜索这个异常,但没有得到任何与我的问题相关的帖子。stackoverflow上的相关问题讲NullPointerException。

I think the problem must be with my library, but I can not point to root cause.

我认为问题一定出在我的图书馆上,但我无法指出根本原因。

Thanks

谢谢

回答by BalusC

This can happen when you have Tomcat-specific JAR files in your webapp's /WEB-INF/lib. This is not right. You should removeall servletcontainer-specific JAR files from there. They do not belong there at all. They are supposed to be alreadyprovided by the servletcontainer itself. The /WEB-INF/libshould only contain libraries specific to the webapp itself which are not provided by the servletcontainer.

当您的 web 应用程序的/WEB-INF/lib. 这个不对。您应该 从那里删除所有 servletcontainer 特定的 JAR 文件。他们根本不属于那里。它们应该已经由 servletcontainer 本身提供。本/WEB-INF/lib应只包含库具体到哪些没有被servletcontainer提供的Web应用程序本身。

If you have placed them there as a result of an unthoughtful attempt to fix compilation errors, then please carefully read this answer how to solve it the right way: How do I import the javax.servlet API in my Eclipse project?

如果您由于不经意地尝试修复编译错误而将它们放在那里,那么请仔细阅读这个答案如何以正确的方式解决它:如何在我的 Eclipse 项目中导入 javax.servlet API?

回答by u1733754

If cleaning your project didn't help, perhaps you need to clear your cache.

如果清理您的项目没有帮助,也许您需要清除缓存

The Netbeans cache is located somewhere...
C:\Documents and Settings\myself.netbeans\7.0\var\cache

Netbeans 缓存位于某处...
C:\Documents and Settings\myself.netbeans\7.0\var\cache

回答by Tejaswini

Remove the following from lib.

从 lib 中删除以下内容。

  1. Check for same jar with different versions
  2. All catalina related jars
  3. el-api.jar
  4. jsp-api.jar
  1. 检查不同版本的同一个jar
  2. 所有与 catalina 相关的 jars
  3. el-api.jar
  4. jsp-api.jar

This will definitely work.

这肯定会奏效。