当前位置:   article > 正文

jakarta.servlet.ServletException: 类com.seig.servlet.HelloServlet不是Servlet_org.apache.catalina.authenticator.authenticatorbas

org.apache.catalina.authenticator.authenticatorbase.invoke(authenticatorbase

在使用servlet的时候遇到一个报错

  1. jakarta.servlet.ServletException: 类com.seig.servlet.HelloServlet不是Servlet
  2.   org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542)
  3.   org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
  4.   org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:693)
  5.   org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:339)
  6.   org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374)
  7.   org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
  8.   org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:845)
  9.   org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1563)
  10.   org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
  11.   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
  12.   java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
  13.   org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
  14.   java.lang.Thread.run(Thread.java:748)
  15.  根本原因。
  16.  ​
  17.  java.lang.ClassCastException: com.kang.servlet.HelloServlet cannot be cast to jakarta.servlet.Servlet
  18.   org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542)
  19.   org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
  20.   org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:693)
  21.   org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:339)
  22.   org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374)
  23.   org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
  24.   org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:845)
  25.   org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1563)
  26.   org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
  27.   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
  28.   java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
  29.   org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)

pom.xml

  1. <dependency>
  2.      <groupId>javax.servlet</groupId>
  3.     <artifactId>javax.servlet-api</artifactId>
  4.      <version>4.0.1</version>
  5.      <scope>compile</scope>
  6.  </dependency>

这是因为使用了最新的tomcat10,而tomcat10有个最大的变动就是Tomcat 10 m1将JavaEE也换成了Jakarta® EE Jakarta® EE较以前的JavaEE有一个非常非常重要的更新:包名不再是"javax.servlet.“而是改成了"jakarta.servlet.” tomcat10之后servlet依赖包名不是javax.servlet,而是jakarta.servlet

可以用以下两个依赖

  1. <dependency>
  2.    <groupId>jakarta.servlet.jsp</groupId>
  3.    <artifactId>jakarta.servlet.jsp-api</artifactId>
  4.    <version>3.0.0</version>
  5.    <scope>provided</scope>
  6.  </dependency>
  1.  <dependency>
  2.    <groupId>jakarta.servlet</groupId>
  3.    <artifactId>jakarta.servlet-api</artifactId>
  4.    <version>5.0.0</version>
  5.    <scope>provided</scope>
  6.  </dependency>

解决方案:或者不使用Tomcat10,改用Tomcat9

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/神奇cpp/article/detail/977498
推荐阅读
相关标签
  

闽ICP备14008679号