关于AJAX在jsp页面使用xmlHttp.responseText方法获取中文 乱码问题

当在jsp页面获取后台传入的中文数据时使用:
var namestatus=xmlHttp.responseText;
获取到的是一串乱码,看了很多的想关解决方案却一直没有解决掉

后面用的这个方法:
在你的后台/Action页面加入:

public ActionForward process(ActionMapping mapping, ActionForm actionForm,
HttpServletRequest request, HttpServletResponse response) 


在你的查询方法中加入(如果不知道加在哪里就加在方法的第一句或者方法的声明下面):

request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=utf-8");

这里注意request和response分别是什么,在上面对应

烦恼解决。

猜你喜欢

转载自blog.csdn.net/weixin_44003632/article/details/86626993