在SSH开发中,使用中文参数类似下面的情况服务器端显示会乱码。

http://localhost:8080/resource/getdata?classify=中文

解决办法:

在tomcat->conf->server.xml中添加URIEncoding=“UTF-8”:

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

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

在controller方法上加上注解:

@ModelAttribute

标签: tomcat, 问题, utf8

添加新评论