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

jsp最上面两句话是


我想将前后台都设为gbk编码,

Prototype.js中updater返回乱码问题处理

     昨天由于项目要求,所有页面需要GB2312编码,只好把数据库和页面UTF8编码都改过来,在改的过程中出现一个问题,就是页面中调用Prototype.js中Ajax.updater方法时候,页面显示的都是乱码。
     今天用了一个上午终于搞定,原来只要在apache的http.conf中添加一行"AddDefaultCharset GB2312",就可以了,这样在xmlhttpd返回的时候就是GB2312编码不是默认的UTF8。
     在此感谢nio的帮助
     舌头已经连续5天上火,导致不能吃什么东西,希望明天可以好了,可以好好吃顿饭
评论
发表评论

您还没有登录,请登录后发表评论

goby2008
搜索本博客
博客分类
最近加入圈子
存档
最新评论