//public Tools(){}
  //把数据库中的中文乱码转化成GBK码
  public static String toGBKString(String s) {
    String str = null;
    if (s == null) {
      s = "";
    }
    try {
      str = new String(s.getBytes("ISO8859_1"), "GBK");
      return str;
    }
    catch (Exception e) {
      return null;
    }
  }

解决方案 »

  1.   

    上面说的也是对的!
    如果你在JSP中有参数的传递,如聊天室什么的也有乱码,应该加上一句!
     request.setCharacterEncoding("GBK");
    用JAVA在网络传递数据时用的是"ISO8859_1"时!
    可是我们的中文数据是GBK,或gb2312!
      

  2.   

    如果你用的是 RESIN ,那么你一定不要用 :str = new String(s.getBytes("ISO8859_1"), "GBK");
    因为RESIN 可以解决。