欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

使用servlet注解开发时,配置了注解不生效的问题解决

程序员文章站 2024-01-11 16:25:22
编写一个servlet类@WebServlet(urlPatterns = "/hello2")public class Hello2Servlet extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { PrintWriter writer =...

编写一个servlet类

@WebServlet(urlPatterns = "/hello2") public class Hello2Servlet extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { PrintWriter writer = resp.getWriter(); writer.println("hello2"); } @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { doGet(req, resp); } } 

但是在部署程序之后访问之,并没有任何效果,依然是404状态

查看web.xml

<?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="true"> </web-app> 

发现metadata-complete="true",将其修改为metadata-complete="false",重新部署程序
访问成功!

本文地址:https://blog.csdn.net/qq754772661/article/details/107875018

相关标签: java servlet