spring过滤器篇

CharacterEncodingFilter

spring的web包下的一个过滤器,用于设置程序的字符编码,它有两个参数encoding和forceEncoding.

encoding:字符集,将过滤到的request编码设置为指定编码

forceEncoding:布尔值,设置是否将response也设置成指定编码

在web.xml中的配置:

  <filter>
      <filter-name>characterEncoding</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>characterEncoding</filter-name>
      <url-pattern>/*</url-pattern>
  </filter-mapping>

 

posted @ 2016-09-28 15:23  冰封绝恋  阅读(223)  评论(0编辑  收藏  举报