web.xml文件中各个配置的说明

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<display-name>mips</display-name>
<welcome-file-list>
<welcome-file></welcome-file>
</welcome-file-list>

 

<!--初始化spring的配置文件,常与ContextLoaderListener监听器一起使用-->
<context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>
    classpath:context.xml,classpath:security.xml
  </param-value>
</context-param>

 

<!--配置web项目的绝对路径,防止多个项目之间造成冲突-->
<context-param>
  <param-name>webAppRootKey</param-name>
  <param-value>mips.root</param-value>
</context-param>

 

<!--配置spring转发器-->
<servlet>
  <servlet-name>springmvc</servlet-name>
  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  <init-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
      classpath:mvc.xml
    </param-value>
  </init-param>
  <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
  <servlet-name>springmvc</servlet-name>
  <url-pattern>/</url-pattern>
</servlet-mapping>


<!--

  spring security必须的配置文件,有以下两点需要注意:

    1、web.xml中配置security必须的过滤器,注意名字必须是springSecurityFilterChain,这是内置的过滤器;然后将过滤规则设置为/*,表示对所有请求都拦截。

    2、关于security的配置文件必须在<context-param>中加入,因为ContextLoaderListener在加载的时候就会去加载security相关的东西,而此时springmvc(servlet)模块还没有初始化。

-->
<filter>
  <filter-name>springSecurityFilterChain</filter-name>
  <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
  <filter-name>springSecurityFilterChain</filter-name>
  <servlet-name>springmvc</servlet-name>
</filter-mapping>

 

<!--配置spring的字符编码集-->
<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>forceEncoding</param-name>
    <param-value>true</param-value>
  </init-param>
</filter>
<filter-mapping>
  <filter-name>characterEncodingFilter</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>

 

<!--contextConfigLocation的监听器-->
<listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>


<session-config>
  <session-timeout>30</session-timeout>
</session-config>


</web-app>

posted @ 2018-04-04 15:43  根须  阅读(900)  评论(0)    收藏  举报