本以为.toUnicode就可以了

结果.........


在前台页面上代码类型是gb2312
而到了Action页里gb2312代码都成了乱码。
于是就要把gb2312代码转换为ISO-8859-1
      // "gb2312"到"ISO-8859-1"的转码 
    public String iso2gb(String str) { 
        try { 
            str = new String(str.getBytes("ISO-8859-1"), "gb2312"); 
        } catch (Exception e) { 
            System.out.println("Encoding Error!"); 
        } 
        return str; 
    } 

然后把ISO-8859-1转换为Unicode

 char[]arChar=iso2gb(sea).toCharArray();
         int iValue=0;
         String uStr="";
         for(int i=0;i<arChar.length;i++){
             iValue=(int)iso2gb(sea).charAt(i);         
             if(iValue<=256){
               // uStr+="�"+Integer.toHexString(iValue)+";";
                 uStr+="\\u00"+Integer.toHexString(iValue);
             }else{
               // uStr+="&#x"+Integer.toHexString(iValue)+";";
                 uStr+="\\u"+Integer.toHexString(iValue);
             }
         }

posted on 2007-11-28 22:37  超少  阅读(3810)  评论(1编辑  收藏  举报