CharacterEncodingFilter这个spring的过滤器

org.springframework.web.filter.CharacterEncodingFilter

对请求于响应的编码进行过滤,半路出家的和尚总是对什么都感觉到好奇,都想记录下来(😂),我好奇的是过滤器也可以设置mapping,下面看两个配置的案例:

案例1(不使用mapping)

<filter>
    <filter-name>encodingFilter</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>

案例2(使用mapping)
<!-- 配置CharacterEncoding,设置字符集 -->
    <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>


posted on 2017-07-25 15:31  blbl9527  阅读(87)  评论(0编辑  收藏  举报

导航


github sina微博 FB