java-tomcat启动后跳转servlet404

问题

  • 在启动tomcat后跳转servlet 404报错
    检查路径后确认没有错误,tomcat配置正确。

解决方法

  • 对于新版本tomcat
    需要把maven的依赖中的javax.servlet更换为jakarta.servlet
    同时web.xml的版本也升级为新版


web.xml配置

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="https://jakarta.ee/xml/ns/jakartaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"
         version="5.0">

</web-app>

jakarta依赖配置

         <dependency>
            <groupId>jakarta.servlet</groupId>
            <artifactId>jakarta.servlet-api</artifactId>
            <version>5.0.0</version>
            <scope>provided</scope>
        </dependency>
posted @ 2023-03-18 14:53  钟音城  阅读(195)  评论(0)    收藏  举报