简介
提交参数和返回数据会乱码,即request.setChrarcterEncoding()和response.setCharacterEncoding()没有设置
解决
SpringMVC中处理
1. 提交参数乱码,通过设置过滤器解决
<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>
2. 响应乱码,通过@RequestMapping(product="(content-type)")解决
@RequestMapping(value = "/spring2",method = RequestMethod.GET,produces = "text/html;charset=utf-8")