Tomcat 设置URI默认字符集为UTF-8

新配置一个Spring的MVC项目,发现对Get请求的中文参数出现了乱码:

Tomcat 设置URI默认字符集为UTF-8_第1张图片

查看了SpingMVC中关于编码的配置(在web.xml中),如下

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

    <filter-mapping>
        <filter-name>encodingFilter</filter-name>
        <servlet-name>appkit</servlet-name>
    </filter-mapping>


应该不是Spring的问题,应该是Tomcat的问题,然后去修改Tomcat的配置文件server.xml,添加URIEncoding="UTF-8"

    <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443"
               URIEncoding="UTF-8"/>
然后就好了




你可能感兴趣的:(Tomcat 设置URI默认字符集为UTF-8)