spring在web.xml中的配置

来源:互联网 发布:aes加密算法c语言实现 编辑:程序博客网 时间:2024/04/29 19:49

  
  <!-- 配置过滤器 需要导入spring的相关jar包-->
  <filter>
    <filter-name>setCharacterEncoding</filter-name>
    <filter-class>
     org.springframework.web.filter.CharacterEncodingFilter.class
    </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>setCharacterEncoding</filter-name>
   <url-pattern>/*</url-pattern>
  </filter-mapping>

 


  
  <!-- 加载多个spring配置文件 -->
  <context-param>
   <param-name>contextConfigLocation</param-name>
   <param-value>
    /WEB-INF/applicationContext.xml,/WEB-INF/action-servlet.xml
   </param-value>
  </context-param>
  <!-- 定义spring监听器,加载spring -->
  <listener>
   <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <!-- 注册spring的request作用域
   request表示该针对每一次HTTP请求都会产生一个新的bean,同时该bean仅在当前HTTP request内有效,配置实例:
   request、session、global session使用的时候首先要在初始化web的web.xml(WebRoot文件下的Web.xml文件)
   中做如下配置:如果你使用的是Servlet 2.4及以上的web容器
   ,那么你仅需要在web应用的XML声明文件web.xml(tomcat中的web.xml)中增加下述ContextListener即可-->
  <listener>
   <listener-class>
    org.springframework.web.context.request.RequestContextListener
   </listener-class>
  </listener>

原创粉丝点击