查看完整版本: [-- Java ajax 中文乱码解决方案 --]

风信Java论坛 ›› ajax 讨论交流中心 ›› Java ajax 中文乱码解决方案 登录 -> 注册

1F Java ajax 中文乱码解决方案   jastby Post by : 2009-06-25 17:47:12.0

好久不用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 解码后 即可得到正确的中文字符串!


风信Java论坛 ›› ajax 讨论交流中心 ›› Java ajax 中文乱码解决方案 登录 -> 注册

查看完整版本: [-- Java ajax 中文乱码解决方案 --]
CopyRight © 2008-2009 JavaWind.Net Studio All Rights Reserved
Powered By JWind.BBS Vesion 1.0.0 Beta1 Processed in 6 ms,0 (Queries)  Gzip enabled
粤ICP备07511478号