代码都没有问题,就是报404错误,原因竟然是版本不兼容,搞了我好长时间,简直麻了!!!
因为我的Tomcat是11版本的,所以导入的servlet和jsp依赖应该是下面这些:
<!-- Servlet API --><dependency><groupId>jakarta.servlet</groupId><artifactId>jakarta.servlet-api</artifactId><version>5.0.0</version><scope>provided</scope></dependency><!-- JSP API --><dependency><groupId>jakarta.servlet.jsp</groupId><artifactId>jakarta.servlet.jsp-api</artifactId><version>3.0.0</version><scope>provided</scope></dependency>
Tomcat7.0版本的相关依赖信息:
<dependency><groupId>javax.servlet</groupId><artifactId>servlet-api</artifactId><version>3.0</version><scope>provided</scope>
</dependency><dependency><groupId>javax.servlet.jsp</groupId><artifactId>jsp-api</artifactId><version>2.2</version><scope>provided</scope>
</dependency>