@WebServlet注解无效访问servlet接口时报404
解决方法3个
第一:将WEB-INF文件夹下的web.xml替换成3.1版本以上的servlet即可
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0"
metadata-complete="false">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
第二:使用urlpatterns属性
@WebServlet(name="Cservlet",urlpatterns="/CServlet"); //第一种写法,使用urlpatterns属性
@WebServlet("/CServlet") //第二种写法,使用value属性
第三方法:更换Tomcat版本(目前我是用这个方法解决的)
资料来源:
https://blog.csdn.net/Vibugs/article/details/89359551
https://blog.csdn.net/qq_45724216/article/details/116307437

浙公网安备 33010602011771号