tomcat下ajax‘post方式提交服务器乱码问题解决方案
关键字: tomcat下ajax‘post方式提交服务器乱码问题解决方案/*
分析:当调用request.getParameter()函数时,会自动进行一次URI的解码过程,
调用时内置的解码过程会导致乱码出现。
而URI 编码两次后,request.getParameter()函数得到的是原信息URI编码一次的内容。
再用可控的解码函数 java.net.URLDecoder.decode()就可解出原始的正确的信息。
*/
var params = encodeURI(encodeURI("method=post&filed=hit&keyword=" + keyword));
createXMLHttpRequest();
var url = "search.do";
xmlHttp.onreadystatechange = handleStateChange;
xmlHttp.open("POST",url,true);
xmlHttp.setRequestHeader("content-length",params.length);
xmlHttp.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.send(params);
服务器端代码:
response.setContentType("text/html;charset=gb2312");
//ajax post传递的时候,一定是用utf8编码的,url 自己可以设定
String keyword = URLDecoder.decode((String)request.getParameter("keyword"),"utf-8");
发表评论
- 浏览: 15764 次

- 详细资料
搜索本博客
最近加入圈子
最新评论
-
java 编写一个扫描仪程序
好象要收费的。
-- by xpf7622 -
[java]比较两个日期之间的 ...
好!!!标准!!
-- by zhang263yy -
jdk+tomcat+mysql+网站(s ...
InstallShield或InstallAnyWhere
-- by FAT0708 -
jdk+tomcat+mysql+网站(s ...
能具体点吗?
-- by xyflash -
jdk+tomcat+mysql+网站(s ...
一般是用批处理文件来做的
-- by ztroma






评论排行榜