关于在 url 里面传递 中文 字符的乱码问题。str = "我是一个猪";
url = 'webmail-busicardedit.do?parm1='str;
window.location.href = url;然后跑到下一个画面 接受到的 str 就是乱码了。请问我如何实现转码啊?URLEncoder.encode或者encodeURI到底怎么用啊?有没有人能说得具体一点啊。谢谢了

解决方案 »

  1.   

    public String toASCII(String str) {
    try {
    if (str == null) {
    str = "";
    } else {
    str = new String(str.getBytes("GBK"), "ISO-8859-1");
    }
    } catch (Exception e) {
    System.out.println("DealString::toGBK(String)运行时出错:错误为:" + e);
    }
    return str;
    }///
    /** 转换编码 */
    public String toGBK(String str) {
    try {
    if (str == null) {
    str = "";
    } else {
    str = new String(str.getBytes("ISO-8859-1"), "GBK");
    }
    } catch (Exception e) {
    System.out.println("DealString::toGBK(String)运行时出错:错误为:" + e);
    }
    return str;
    }
      

  2.   

    http://community.csdn.net/Expert/topic/5238/5238411.xml?temp=.6575128
    ------------
    这个连接我发了3,4次了。
    希望对你有帮助。
      

  3.   

    str = ='<%=urlencoder.encode("我是一个猪","utf-8")%>'
    url = 'webmail-busicardedit.do?parm1='+str;  //你少写了个+
    window.location.href = url;