ajax取SpringMVC的response乱码问题
使用SpringMVC开发web项目的时候,用到了ajax与其交互,但是返回的response中中文参数获取乱码。
使用拦截器
java代码:自定义创建一个拦截器,继承HandlerInterceptorAdapter
public class CommonInterceptor extends HandlerInterceptorAdapter { @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) { response.setContentType("text/json;charset=UTF-8"); response.setCharacterEncoding("UTF-8"); return true; } }
需要从spring-mvc.xml中配置如下:
放在<beans>节点内
<mvc:interceptors> <bean class="com.wsv.common.CommonInterceptor" /> </mvc:interceptors>
相关推荐
86193952 2020-10-27
Mynamezhuang 2020-09-18
充满诗意的联盟 2020-08-23
raksmart0 2020-08-17
yfightfors 2020-08-16
84487600 2020-08-16
qdqht00 2020-07-26
WebVincent 2020-07-21
hzyuhz 2020-07-04
fengchao000 2020-07-04
javaraylu 2020-06-28
baijinswpu 2020-06-28
ZHANGRENXIANG00 2020-06-28
Teamomc 2020-06-28
Catastrophe 2020-06-26
hell0kitty 2020-06-17
我欲疾风前行 2020-06-18