Response.Write(Server.URLEncode("http://www.microsoft.com")) 
结果:
http%3A%2F%2Fwww%2Emicrosoft%2Ecom

解决方案 »

  1.   

    Response.Write(Server.URLEncode("http://www.microsoft.com")) 
    结果:
    http%3A%2F%2Fwww%2Emicrosoft%2Ecom
      

  2.   

    unescape 方法
    解码用 escape 方法进行了编码的 String 对象。 unescape(charstring) 必选项 charstring 参数是要解码的 String 对象。 说明
    unescape 方法返回一个包含 charstring 内容的字符串值。所有以 %xx 十六进制形式编码的字符都用 ASCII 字符集中等价的字符代替。 以 %uxxxx 格式(Unicode 字符)编码的字符用十六进制编码 xxxx 的 Unicode 字符代替. 注意   unescape 方法不能用于解码统一资源标识码 (URI)。解该码可使用 decodeURI 和 decodeURIComponent 方法。escape 方法
    对 String 对象编码以便它们能在所有计算机上可读, escape(charString)必选项 charstring 参数是要编码的任意 String 对象或文字。 说明
    escape 方法返回一个包含了 charstring 内容的字符串值( Unicode 格式)。所有空格、标点、重音符号以及其他非 ASCII 字符都用 %xx 编码代替,其中 xx 等于表示该字符的十六进制数。例如,空格返回的是 "%20" 。字符值大于 255 的以 %uxxxx 格式存储。 注意   escape 方法不能够用来对统一资源标示码 (URI) 进行编码。对其编码应使用 encodeURI 和encodeURIComponent 方法。
    encodeURI 方法
    将文本字符串编码为一个有效的统一资源标识符 (URI)。encodeURI(URIString)必选的 URIString 参数代表一个已编码的 URI。说明
    encodeURI 方法返回一个编码的 URI。如果您将编码结果传递给 decodeURI,那么将返回初始的字符串。encodeURI 方法不会对下列字符进行编码:":"、"/"、";" 和 "?"。请使用 encodeURIComponent 方法对这些字符进行编码。
      

  3.   

    感谢二位大哥捧场!我的具体问题是这样产生的:
    <% 
     String tempThechat = URLEncoder.encode("测试");
    %><script language="JavaScript"><!--
      var thechat = '<%= tempThechat %>';
      function execute()
      {
        self.parent.dbcontent.document.open("text/html");
        self.parent.dbcontent.document.writeln(thechat);
        self.parent.dbcontent.document.write();
        self.parent.dbcontent.document.close();
      }
    </script>当tempThechat中包含中文时,用writeln写出来的中文就是乱码,怎么解决呢?