转换一下,string.getBytes("ISO8859-1")

解决方案 »

  1.   

    一般从数据库读数据需要转换以下! 用下面的方法~
    String trans(String chi)
    {
                   String result = null;
                   byte temp [];
                   try
                   {
                           temp=chi.getBytes("iso-8859-1");
                          result = new String(temp,"GBK");
                    }
                    catch(UnsupportedEncodingException e)
                    {
                            System.out.println (e.toString());
                    }
    return result;
    }
    String 参数为读出来的数据
      

  2.   

    常用字符集: GBK,GB2312, UTF-6, ISO-8859-1  转换用户输入信息字符集
    request.setCharacterEncoding(“UTF-8”);
    request.getParameter("value").getBytes("8859_1"),"gb2312");
     转换输出信息字符集
    new String(str.getBytes("GB2312"),"ISO-8859-1");
    new String(str.getBytes(" ISO-8859-1 "),“GBK");
    request.setCharacterEncoding("UTF-8"); 
     读取数据库数据
    str=new String(str.getBytes("GB2312"));
     插入数据库数据
    str=new String(str.getBytes("ISO-8859-1"));
      

  3.   

    两台机子上的Win2K,TOmcat ,MSSQL默认的字符集都是一样的么?如果不行,你就转换一下,中文的问题有时候就是不方便的。