Tomcat(9) 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">
<!-- 定义上下文参数 -->
<context-param>
<param-name>appName</param-name>
<param-value>MyWebApp</param-value>
</context-param>
<!-- 定义Servlet -->
<servlet>
<servlet-name>HelloWorldServlet</servlet-name>
<servlet-class>com.example.HelloWorldServlet</servlet-class>
<init-param>
<param-name>message</param-name>
<param-value>Welcome to My Web App!</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- 映射Servlet到URL -->
<servlet-mapping>
<servlet-name>HelloWorldServlet</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>
<!-- 设置欢迎页面 -->
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<!-- 设置错误页面 -->
<error-page>
<error-code>404</error-code>
<location>/error/404.jsp</location>
</error-page>
<!-- 配置会话超时 -->
<session-config>
<session-timeout>30</session-timeout>
</session-config>
</web-app>