<s:textfield id="tzid" name="bo.tzid"/>
这是前台jquery 操作,提交数据给action后台处理
 //提交操作(添加,删除,修改)
         $.getJSON("setProxy!Save.action?"+encodeURI($("form").serialize()),null,function(json){
       if(null!=json&&json.length==1&&json[0].opare=="0")
       {
       $("#tzid").val(json.tzid);
       alert("保存成功!"+$("#tzid").val()+"==>>");
       EnContrl();
       modeRest();
       }else if(null!=json&&json.length==1&&json[0].opare!="0")
       {
       alert("保存失败!");
       }
});
这是后台
    boo bo; //get,set封装都有    public String doSave() {
        int opare = 0;
        try {
            User user = this.getSessionUser();
            if (null != bo.getTzid() && !"".equals(bo.getTzid())) {
                this.getDao().edit(bo, user, this.getConn());
            } else {
                this.getDao().add(bo, user, this.getConn());
            }
           this.outPrint("[{\"opare\":\"" + opare + "\",\"tzid\":\"" + bo.getTzid() + "\"}]");
         }catch(Exception e){}
  }
 数据库数据中文乱码试了几种方案都不行:
1.queryBean.setName(URIUtil.encodeQuery(queryBean.getName()))
2.new String(str.getBytes("ISO-8859-1"), "gb2312")
3.<constant name="struts.i18.encoding" value="utf-8"></constant>
4.<Connector port="8080" protocol="HTTP/1.1" 
               connectionTimeout="20000" 
               redirectPort="8443" URIEncoding="GBK"/>实在是没招了,所以请各位大虾帮忙出一招?

解决方案 »

  1.   

    是传到后台变乱码?还是存入数据以后变乱码的?可能是数据库类型的问题~把数据库类型改nvarchar呢?
      

  2.   

    二楼回复:
      前台通过 $.getJSON( "setProxy!Save.action? "+encodeURI($( "form ").serialize()),null,function(json){ 
      到action里面的时候就是中文乱码
    三楼回复:
       过滤器全都配制,可就是收到的数据是中文乱码!
      

  3.   

    有中文的话这样encodeURI(encodeURI(obj)
      

  4.   

    后台用这个java.net.URLDecoder.decode(obj, "UTF-8");
      

  5.   

    终于找到答案了,谢谢大家的关注!答案如下:
    在tomact中配制这个
    <Connector port="8080" protocol="HTTP/1.1" 
                   connectionTimeout="20000" 
                   redirectPort="8443" URIEncoding="GBK" useBodyEncodingForURI="true" />
    然后再把JSP页面的编码格式写成GBK,以及页面属性也要改成BGK!这样就行了!
    因为我用的struts2集成的,ognl里面自带转码填充的!