<?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"><servlet><servlet-name>RegistServlet</servlet-name><servlet-class>com.ly.web.RegistServlet</servlet-class></servlet><servlet-mapping><servlet-name>RegistServlet</servlet-name><url-pattern>registServlet</url-pattern></servlet-mapping> </web-app>
url-pattern就是说的url模式,就是容器在查找时根据这个模式来找到具体的servlet来执行
url模式的一种格式为<url-pattern>/</url-pattern>
上面出现的错误在registServlet前加“/”即可解决(这个“/”表示该项目的工程路径如http://localhost:8080/项目名称/)
<?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"><servlet><servlet-name>RegistServlet</servlet-name><servlet-class>com.ly.web.RegistServlet</servlet-class></servlet><servlet-mapping><servlet-name>RegistServlet</servlet-name><url-pattern>/registServlet</url-pattern></servlet-mapping> </web-app>