最新SpringMVC 4,如何解决@ResponseBody时,String类型乱码
1个回答
展开全部
web.xml里头添加如下代码,改成你使用的编码
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter
</filter-class>
<init-param>
<!-- 等价于ServletRequest.setCharacterEncoding(java.lang.String) -->
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<!-- 追加设置ServletResponse的编码格式同ServletRequest的编码格式一致
即response.setCharacterEncoding(“XXXX”),认值为false -->
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询