启动一个WEB项目的时候,容器(如:Tomcat)会去读它的配置文件web.xml.
读两个节点: <context-param></context-param> 和<listener></listener>
context-param 属性1 加载的名称 属性2 加载的路径
- 设置内存监听器
此监听器主要用于解决java.beans.Introspector导致的内存泄漏的问题
此监听器应该配置在web.xml中与Spring相关监听器中的第一个位置(也要在ContextLoaderListener的前面)
<listener>
<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener>
- 监听spring核心配置文件
ContextLoaderListener 该类的作用就是自动装载ApplicationContext的配置信息
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/src/main/resources/applicationContext.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
2.监听器 读取log4j
log4jRefreshInterval 扫描间隔 每6秒扫描一次
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:log4j.properties</param-value>
</context-param>
<context-param>
<param-name>log4jRefreshInterval</param-name>
<param-value>6000</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
3.配置前端控制器DispatcherServlet
init-param 初始参数 加载配置文件
load-on-starup 加载优先级 越小 优先级越高
<servlet>
<servlet-name>cryq</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springMVC.xml</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
4.http转换8种方式
CREATE :PUT
READ:GET
UPDATE:POST
DELETE:DELETE
<filter>
<filter-name>hiddenHttpMethodFilter</filter-name>
<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>hiddenHttpMethodFilter</filter-name>
<servlet-name>cryq</servlet-name>
</filter-mapping>
5.解决post乱码问题
有三个属性 属性1:编码设置 utf-8 属性2 : 强制请求编码 属性3 : 强制想赢编码
<filter>
<filter-name>characterEncodingFilter</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>
<init-param>
<param-name>forceRequestEncoding</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>forceResponseEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>characterEncodingFilter</filter-name>
<servlet-name>cryq</servlet-name>
</filter-mapping>