1、环境:
idea 2020.1
window 10
java se 1.8.0_271
2、目录结构
3、示例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">
<servlet>
<!-- servlet-name标签中的内容,代表这个servlet的别名,可以是随便取值,但是习惯上用类名-->
<servlet-name>ServerletDemo</servlet-name>
<!-- servlet-class标签中的内容,代表这个servlet对应的类的全类名-->
<servlet-class>com.serverlet.ServletDemo</servlet-class>
</servlet>
<!-- servlet-mapping标签将servlet与url相对应-->
<servlet-mapping>
<!-- serlet-name标签中的内容,代表这个mapping所对应的servlet的别名-->
<servlet-name>ServerletDemo</servlet-name>
<!-- url-pattern标签的内容,表示通过这个url可以访问到这个mapping所代表的servlet-->
<url-pattern>/hello</url-pattern>
</servlet-mapping>
</web-app>