str = new String(str.getBytes("iso8859-1"), "gbk");
我参数是从JSP页面传过来的,在window下后天这样能正常得到中文而到了linux下后台得到的却是乱码我换了这样的写法
str = new String(str.getBytes("gbk"), "iso8859-1");
得到了正常的中文
请问这是为什么linux下的服务器是weblogic的,linux系统的默认字符集为ISO8859-1.
请高手帮忙解释一下

解决方案 »

  1.   

    Constructs a new String by decoding the specified array of bytes using the specified charset. The length of the new String is a function of the charset, and hence may not be equal to the length of the byte array. 
    The behavior of this constructor when the given bytes are not valid in the given charset is unspecified. The java.nio.charset.CharsetDecoder class should be used when more control over the decoding process is required.Parameters:
    bytes The bytes to be decoded into characters
    charsetName The name of a supported charset这个是new String(byte[] bytes, String charsetname)的说明,linux系统的默认字符集为ISO8859-1,所以要把字符串转成ISO8859-1的字符集才能正常识别。
      

  2.   

    操作系统默认字符集会成为JSP对请求解参时使用的字符集。
    不要这样转码,用Servlet或Filter的request.setCharactorEncoding()是正解。
      

  3.   

    引用jdk的解释
    ======================================================
    public String(byte[] bytes,  String charsetName)
           throws UnsupportedEncodingException通过使用指定的 charset 解码指定的 byte 数组,构造一个新的 String。新 String 的长度是字符集的函数,因此可能不等于 byte 数组的长度。 getBytes(String charsetName)
                    throws UnsupportedEncodingException使用指定的字符集将此 String 编码为 byte 序列,并将结果存储到一个新的 byte 数组中。 
      

  4.   

    引用jdk的解释
    ======================================================
    public String(byte[] bytes, String charsetName)
      throws UnsupportedEncodingException通过使用指定的 charset 解码指定的 byte 数组,构造一个新的 String。新 String 的长度是字符集的函数,因此可能不等于 byte 数组的长度。  getBytes(String charsetName)
      throws UnsupportedEncodingException使用指定的字符集将此 String 编码为 byte 序列,并将结果存储到一个新的 byte 数组中。 
    操作系统默认的字符编码 确实需要转换字符集的。