技术社区
回复列表
-
0092020-02-15
1. get乱码,手动转换
首先: String name = new String(xx.getBytes(“iso-8859-1”),”utf-8”);
不行的化,再: 在server.xml中,修改编码和工程编码一致
2. post乱码,在web.xml中配置字符过滤的filter,采用的类是Spring的CharacterEncodingFilter
<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>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
原因:
使用注解@RequestBody和@ResponseBody时,request.setCharactorEncoding(“utf-8”),不起作用。