我也一直在找这个解决方法,但是没有找到。
如果你知道后,请发一份给我。([email protected])谢谢!

解决方案 »

  1.   

    bbs.ntsky.com
    整个网站全部采用了utf-8,从数据库到bean,到前台的jsp,但有个问题没解决,就是浏览器上传递中文我一直找不到办法解决。
      

  2.   

    str1 = new String(str.getBytes("UTF-8"),gb2312);
      

  3.   

    轉成簡體:
    str1 = new String(str.getBytes("UTF-8"),gb2312);
    轉成繁體:
    str1 = new String(str.getBytes("UTF-8"),big5);
    ……
    如此
      

  4.   

    楼上的,你们的方法不行啊,我的方法是这样写的
    public static String toGbkString(String s) {
        String temp = new String(s.getBytes("utf-8"),gb2312);
        return temp;
    }显示的错误是“无法解析gb2312”,String的构造函数里面有这种方法吗?
    对了,我的JDK是1.4.1
      

  5.   

    把gb2312加引号,还有,别忘了处理java.io.UnsupportedEncodingException异常
      

  6.   

    你们的方法不行~我简单说明一下我的要求,比如说中文“你好,世界”转化为和google一样的编码为“%E4%BD%A0%E5%A5%BD%EF%BC%8C%E4%B8%96%E7%95%8C”
    我现在需要的是怎么把%E4%BD%A0%E5%A5%BD%EF%BC%8C%E4%B8%96%E7%95%8C转化为中文
      

  7.   

    都是自己写的~~~JSP容器是JBOSS~~
      

  8.   

    String temp = new String(s.getBytes("UTF_8"),"gb2312");应该没什么问题的,你再看看,我就是这样用的
      

  9.   

    不行的~~你自己试试啊~~
    把“%E4%BD%A0%E5%A5%BD%EF%BC%8C%E4%B8%96%E7%95%8C”转化为中文
      

  10.   

    public static String toGbkString(String s) { StringBuffer sb = new StringBuffer();
    byte[] b = new byte[3];
    int temp;
    int index;
    try {
    while (s.length() != 0) {
    index = s.indexOf("%");
    if (index == -1)
    return sb.append(s).toString();
    if (index != 0) {
    sb.append(s.substring(0, index));
    }
    if (index + 9 <= s.length()) {
    temp =
    Integer.parseInt(s.substring(index + 1, index + 3), 16)
    - 256;
    b[0] = Byte.parseByte(String.valueOf(temp));
    temp =
    Integer.parseInt(s.substring(index + 4, index + 6), 16)
    - 256;
    b[1] = Byte.parseByte(String.valueOf(temp));
    temp =
    Integer.parseInt(s.substring(index + 7, index + 9), 16)
    - 256;
    b[2] = Byte.parseByte(String.valueOf(temp)); sb.append(new String(b, "utf-8"));
    index += 9;
    s = s.substring(index);
    } else {
    System.out.println("数据格式错误");
    return null;
    }
    }
    } catch (UnsupportedEncodingException ue) {
    System.out.print("can't convert to gb2312 : " + ue.getMessage());
    } catch (NumberFormatException ne) {
    System.out.print("can't convert to gb2312 : " + ne.getMessage());
    }
    return sb.toString();
    }
      

  11.   

    String temp="你好";
    temp = new String(temp.getBytes("utf-8"), "gb2312");
    System.out.print(temp);显示为乱码,更不用说当temp = %E4%BD%A0%E5%A5%BD%EF%BC%8C%E4%B8%96%E7%95%8C 的情况了,都是乱码
      

  12.   

    你的字符集搞乱了.   java里面是unicode码?   而jsp里面要看你指定了
      

  13.   

    native2ascii -reverse inputFile outputFilehttp://www.javayou.com
      

  14.   

    这是VB的,你自己拿去改一下吧,
    <%
    '将UTF-8编码汉字转换为GB2312码,兼容英文和数字
    function UTF2GB(UTFStr)
    for Dig=1 to len(UTFStr)
    if mid(UTFStr,Dig,1)="%" then
    if len(UTFStr) >= Dig+8 then
    GBStr=GBStr & ConvChinese(mid(UTFStr,Dig,9))
    Dig=Dig+8
    else
    GBStr=GBStr & mid(UTFStr,Dig,1)
    end if
    else
    GBStr=GBStr & mid(UTFStr,Dig,1)
    end if
    next
    UTF2GB=GBStr
    end functionfunction ConvChinese(x) 
    A=split(mid(x,2),"%")
    i=0
    j=0
    for i=0 to ubound(A) 
    A(i)=c16to2(A(i))
    next
    for i=0 to ubound(A)-1
    DigS=instr(A(i),"0")
    Unicode=""
    for j=1 to DigS-1
    if j=1 then 
    A(i)=right(A(i),len(A(i))-DigS)
    Unicode=Unicode & A(i)
    else
    i=i+1
    A(i)=right(A(i),len(A(i))-2)
    Unicode=Unicode & A(i) 
    end if 
    next
    if len(c2to16(Unicode))=4 then
    ConvChinese=ConvChinese & chrw(int("&H" & c2to16(Unicode)))
    else
    ConvChinese=ConvChinese & chr(int("&H" & c2to16(Unicode)))
    end if
    next
    end functionfunction c2to16(x)
    i=1
    for i=1 to len(x)  step 4 
    c2to16=c2to16 & hex(c2to10(mid(x,i,4))) 
    next
    end function 

    function c2to10(x)
    c2to10=0
    if x="0" then exit function
    i=0
    for i= 0 to len(x) -1
    if mid(x,len(x)-i,1)="1" then c2to10=c2to10+2^(i)
    next 
    end functionfunction c16to2(x)
    i=0
    for i=1 to len(trim(x)) 
    tempstr= c10to2(cint(int("&h" & mid(x,i,1))))
    do while len(tempstr)<4
    tempstr="0" & tempstr
    loop
    c16to2=c16to2 & tempstr
    next
    end functionfunction c10to2(x)
    mysign=sgn(x)
    x=abs(x)
    DigS=1
    do 
    if x<2^DigS then
    exit do
    else
    DigS=DigS+1
    end if
    loop
    tempnum=x

    i=0
    for i=DigS to 1 step-1
    if tempnum>=2^(i-1) then
    tempnum=tempnum-2^(i-1)
    c10to2=c10to2 & "1"   
    else
    c10to2=c10to2 & "0"
    end if
    next
    if mysign=-1 then c10to2="-" & c10to2
    end function
    %>
      

  15.   

    /*****************************
         方法名称:gb2utf
         参数:String gbStr - GB2312编码字串
         返回值类型:String
         说明:转码,从GB2312转到UTF8
         *****************************/
        public String gb2utf(String gbStr)
        {
        byte[] tempStr;
        String utfStr=new String("");
        try {
            tempStr=gbStr.getBytes("ISO8859-1");
            utfStr = new String(tempStr,"GBK");
        }
        catch (UnsupportedEncodingException uee){
            System.out.println("Exception: "+uee);
        }
        return utfStr;
        }    /*****************************
         方法名称:utf2gb
         参数:String utfStr - GB2312编码字串
         返回值类型:String
         说明:转码,从UTF8转到GB2312
         *****************************/
        public String utf2gb(String utfStr)
        {
        byte[] tempStr;
        String gbStr=new String("");
        try {
            tempStr=utfStr.getBytes("GBK");
            gbStr = new String(tempStr,"ISO8859-1");
        }
        catch (UnsupportedEncodingException uee){
            System.out.println("Exception: "+uee);
        }
        return gbStr;
        }