JavaEE tomcat10踩坑記錄

1. 工具介紹

  1. tomcat: stable 10.0.6
  2. IDEA 2021.1.1
  3. maven: stable 3.8.1

2. 過程描述

  1. 使用idea直接建立項目選用java enterprise
  2. 項目自動生成pom文件, 引入servlet-api的依賴java

    1. <dependency>
           <groupId>javax.servlet</groupId>
           <artifactId>javax.servlet-api</artifactId>
           <version>4.0.1</version>
           <scope>provided</scope>
  3. 編寫項目沒有問題, 運行項目之後靜態資源沒問題,servlet報錯apache

    HTTP狀態 500 - 內部服務器錯誤
    
        ------
    
        **類型** 異常報告
    
        **消息** 實例化Servlet類[com.xrluo.ee.HelloServlet]異常
    
        **描述** 服務器遇到一個意外的狀況,阻止它完成請求。
    
        **例外狀況**
    
        jakarta.servlet.ServletException: 實例化Servlet類[com.xrluo.ee.HelloServlet]異常
            org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:543)
            org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
            org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:690)
            org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:353)
            org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374)
            org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
            org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:870)
            org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1696)
            org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
            java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
            java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
            org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
            java.lang.Thread.run(Thread.java:748)
        **根本緣由。**
        java.lang.NoClassDefFoundError: javax/servlet/http/HttpServlet
            java.lang.ClassLoader.defineClass1(Native Method)
            java.lang.ClassLoader.defineClass(ClassLoader.java:763)
            java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
            org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:2470)
            org.apache.catalina.loader.WebappClassLoaderBase.findClass(WebappClassLoaderBase.java:866)
            org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1370)
            org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1224)
            org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:543)
            org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
            org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:690)
            org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:353)
            org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374)
            org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
            org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:870)
            org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1696)
            org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
            java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
            java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
            org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
            java.lang.Thread.run(Thread.java:748)
    
        **根本緣由。**
        java.lang.ClassNotFoundException: javax.servlet.http.HttpServlet
            org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1401)
            org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1224)
            java.lang.ClassLoader.defineClass1(Native Method)
            java.lang.ClassLoader.defineClass(ClassLoader.java:763)
            java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
            org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:2470)
            org.apache.catalina.loader.WebappClassLoaderBase.findClass(WebappClassLoaderBase.java:866)
            org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1370)
            org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1224)
            org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:543)
            org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
            org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:690)
            org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:353)
            org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374)
            org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
            org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:870)
            org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1696)
            org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
            java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
            java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
            org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
            java.lang.Thread.run(Thread.java:748)

3. 解決問題

目前迷茫中,理論來講maven會下載項目所須要的依賴, 爲何還會與tomcat裏面的httpServlet有關係??api

一樣遇到坑的小夥伴的文章:
Tomcat10的坑tomcat

歡迎大佬解答服務器

相關文章
相關標籤/搜索