好久不用ajax,今天需要用到,却因为提交的中文乱码问题郁闷了半天,特整理出来与大家分享!
ajax Js 客户端:
var data = "words="+encodeURI(encodeURI(_word));   //  注意,这里把需要提交的中文字符串进行两次encodeURI
xmlhttp.open("post",postAction, true);   
xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
xmlhttp.send(data);
ajax Java 服务器端:
String words= request.getParameter("words");
words= java.net.URLDecoder.decode(words, "UTF-8");
通过 URLDecoder.decode 解码后 即可得到正确的中文字符串!






 阿云:
 阿云: 粤ICP备2023102220号-2
 粤ICP备2023102220号-2