SpringMVC中web.xml配置详解
web.xml配置文件是web项目的核心文件,是web项目的入口文件,web项目的启动从这里开始
头约束配置
<?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_3_1.xsd"
version="3.1">
</web-app>
项目名称
<display-name> com.qd.demo </display-name>
加载spring核心配置文件
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:application.xml</param-value>
</context-param>
springmvc配置
<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:spring-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>/</url-pattern> //拦截所有url
</servlet-mapping>
配置编码过滤器
<filter>
<filter-name>setCharacterEncoding</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>setCharacterEncoding</filter-name>
<url-pattern>/</url-pattern>
</filter-mapping>
监听器,可以配置多个
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
session超时时间,单位分钟
<session-config>
<session-timeout>60</session-timeout>
</session-config>
指定欢迎文件
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>