通过ajax提交请求,返回的response所带的中文字符串一直显示为乱码,写了如下代码也无效:
response.setCharacterEncoding("UTF-8");
response.getWriter().print("返回结果");
后来在web.xml 添加如下描述,终于解决问题:
<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> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter>