windows 环境下,JDK的默认编码为 GBK
redhat  环境下,JDK的默认编码为 ?   通过查询JDK信息可知如果不是GBK,就会 在windows下是能正常显示的,在redhat下就不行了
你只需要 进行内码转换 就可以了

解决方案 »

  1.   

    试一下下面的,应该可以:
    首先,调用下面的GBToUnicode()方法将页面上的GB码的字符转换为Unicode码的字符存到数据库中:
    public static String GBToUnicode(String pstrIn){ 
    String strOut = null; 
    if(pstrIn == null || (pstrIn.trim()).equals(""))return pstrIn; 
    try{ 
    byte[] b = pstrIn.getBytes("ISO8859_1"); 
    strOut = new String(b,"GBK"); 
    }catch(Exception e){ } 
    return strOut; 

    显示数据库中的数据时,将数据库中的Unicode码的数据转换为GB码显示。
    public static String UnicodeToGB(String pstrIn){ 
    byte[] b; 
    String strOut = null; 
    if(pstrIn == null || (pstrIn.trim()).equals("")) 
    return pstrIn; 
    try{ 
    b=pstrIn.getBytes("GBK"); 
    strOut=new String(b,"ISO8859_1"); 
    }catch(UnsupportedEncodingException e){} 
    return strOut; 
    }
      

  2.   

    String xxx=request.getParameter("xxx");
    …………
    PreparedStatement ps=conn.prepareStatement(……);
    ps.setBytes(1,xxx.getBytes("gb2312"))
    …………
      

  3.   

    hou_jg(中国龙) :
    通过这样转换,在windows下又不能正常显示了:(
      

  4.   

    1、你的代码ps.setBytes(1,xxx.getBytes("GBK"))要改为ps.setBytes(1,xxx.getBytes("ISO-8859-1"))
    2、去掉“charset=gb2312”
      

  5.   

    3、在页面中加入<meta HTTP-EQUIV=Content-Type content="text/html;charset=GBK">