Servlet获取Ajax POST数据乱码的一种解法(转)
1. 对中文参数编码encodeURI(chinesePara);
poststr = "username="+ ("中文");
2.服务器端获取参数后解码
String username = new String( request.getParameter("username").getBytes("ISO-8859-1"),"UTF8");
-----------------------------------------------------------
http_request.open("POST", url, true);
http_request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
http_request.send(poststr);
本文介绍了一种解决Ajax POST请求中中文数据乱码的方法。客户端通过encodeURI对中文参数进行编码,服务器端使用ISO-8859-1编码获取参数后再转换为UTF-8。此方案适用于前后端交互过程中遇到的字符集不一致导致的数据乱码问题。

被折叠的 条评论
为什么被折叠?



