SpringMVC学习系列-后记 解决GET请求时中文乱码的问题

1. post请求乱码解决:

      在web.xml配置如下过滤器即可,但是get请求却不行...

<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>

tomacat对GET和POST请求处理方式是不同的,要处理针对GET请求的编码问题,则需要改tomcat的server.xml配置文件,如下:

<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>

改为:

<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" useBodyEncodingForURI="true"/>

 

posted on 2016-03-24 17:19  babyblue  阅读(233)  评论(0编辑  收藏  举报