2007-06-04
Prototype乱码问题
jsp页面
function search()
{
var objA=$("id1");
var txt1=$("txt1");
//alert(txt1.value);
var url='http://localhost:8089/testAction.do?method=test';
var pars='txt1='+txt1.value;
//alert(pars);
var myAjax = new Ajax.Request(
url,
{
method:'post',
//requestHeader: ['Content-Type','application/x-www-form-urlencoded'], //---------------- C
parameters:pars,
onComplete:showResponse
}
);
回调函数
function showResponse(prototype)
{
var txtA = prototype.responseText;
alert("从服务器返回的值:"+txtA);
}
Action里
request.setCharacterEncoding("gbk");
String txt1 = request.getParameter("txt1");
System.out.println("转换前:"+txt1); ////-----------------A
txt1 = new String(txt1.getBytes("ISO8859_1"),"gbk");
PrintWriter printWriter = response.getWriter();
System.out.println("转换后:"+txt1); ////-----------------B
printWriter.write(""+txt1+"");
这样,在A就乱码了, B处也会乱
如果采取get方式提交数据,则不会报错, A 处虽然乱了,但 转换后 B处能正确显示
C处,我看了Ajax的资料,上面说 用post提交要加这个参数'Content-Type','application/x-www-form-urlencoded'
所以我加了,不过加了后还是不行,我想,用了框架应该不需要这个了吧,,
tomact5.5.9 jdk 1.5 Eclipse3.2+MyEclipse5.0M2
function search()
{
var objA=$("id1");
var txt1=$("txt1");
//alert(txt1.value);
var url='http://localhost:8089/testAction.do?method=test';
var pars='txt1='+txt1.value;
//alert(pars);
var myAjax = new Ajax.Request(
url,
{
method:'post',
//requestHeader: ['Content-Type','application/x-www-form-urlencoded'], //---------------- C
parameters:pars,
onComplete:showResponse
}
);
回调函数
function showResponse(prototype)
{
var txtA = prototype.responseText;
alert("从服务器返回的值:"+txtA);
}
Action里
request.setCharacterEncoding("gbk");
String txt1 = request.getParameter("txt1");
System.out.println("转换前:"+txt1); ////-----------------A
txt1 = new String(txt1.getBytes("ISO8859_1"),"gbk");
PrintWriter printWriter = response.getWriter();
System.out.println("转换后:"+txt1); ////-----------------B
printWriter.write(""+txt1+"");
这样,在A就乱码了, B处也会乱
如果采取get方式提交数据,则不会报错, A 处虽然乱了,但 转换后 B处能正确显示
C处,我看了Ajax的资料,上面说 用post提交要加这个参数'Content-Type','application/x-www-form-urlencoded'
所以我加了,不过加了后还是不行,我想,用了框架应该不需要这个了吧,,
tomact5.5.9 jdk 1.5 Eclipse3.2+MyEclipse5.0M2
jsp最上面两句话是
我想将前后台都设为gbk编码,
我想将前后台都设为gbk编码,
Prototype.js中updater返回乱码问题处理
昨天由于项目要求,所有页面需要GB2312编码,只好把数据库和页面UTF8编码都改过来,在改的过程中出现一个问题,就是页面中调用Prototype.js中Ajax.updater方法时候,页面显示的都是乱码。
今天用了一个上午终于搞定,原来只要在apache的http.conf中添加一行"AddDefaultCharset GB2312",就可以了,这样在xmlhttpd返回的时候就是GB2312编码不是默认的UTF8。
在此感谢nio的帮助
舌头已经连续5天上火,导致不能吃什么东西,希望明天可以好了,可以好好吃顿饭
发表评论
- 浏览: 15758 次

- 详细资料
搜索本博客
最近加入圈子
最新评论
-
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






评论排行榜