POST乱码
服务端取出参数时发现汉字乱码。解决方法有二种,可以写一个过虑器,调用request.setCharacterEncoding("UTF-8")
,或者直接用spring提供的过虑器:
<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>
GET乱码
修改TOMCAT/conf/server.xml
文件,在connector
标签中添加一个URIEncoding="UTF-8"
属性:
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
URIEncoding="UTF-8" />
如果用的JBoss,那么GET应该不会中文乱码。