zoukankan      html  css  js  c++  java
  • web编码

    1各种编码

    A .1 html编码  -HTML标签

    this.Response.Write(this.Server.HtmlEncode("<h1>的作用将文本设置为标题样式!"));//使< 和 > 等等的特殊符号,已文本性质显示

    输出:<h1>的作用将文本设置为标题样式!

    A.2不用html编码 -HTML标签

     this.Response.Write(this.Server.HtmlDecode("&lt;h1&gt;的作用将文本设置为标题样式!&lt;/h1&gt;"));//特殊符号,已文本性质显示

    B html解码 -HTML标签

     直接显示标题的效果

    this.Response.Write("&lt;h1&gt;的作用将文本设置为标题样式!"); //已标签性质显示的特殊符号

    输出:

    的作用将文本设置为标题样式!

    C url编码  -URL进行编码

    string str=this.Server.UrlEncode("我是一段包含中文的文字!,fs.efe,gr./ht");
    //将中文的文字和标点符号 ,转换成乱码形式,如果直接是字母或数字则不会进行乱码转换
    this.Response.Write(this.Server.UrlEncode(str));

    输出:%25e6%2588%2591%25e6%2598%25af%25e4%25b8%2580%25e6%25ae%25b5%25e5%258c%2585%25e5%2590%25ab%25e4%25b8%25ad%25e6%2596%2587%25e7%259a%2584%25e6%2596%2587%25e5%25ad%2597%25ef%25b

    d url解码 -URL进行编码

    //将转换后的乱码,再次转换回中文的文字和标点符号
    string str=this.Server.UrlDecode("%25e6%2588%2591%25e6%2598%25af%25e4%25b8%2580%25e6%25ae%25b5%25e5%258c%2585%25e5%2590%25ab%25e4%25b8%25ad%25e6%2596%2587%25e7%259a%2584%25e6%2596%2587%25e5%25ad%2597%25ef%25bc%2581%252cfs.efe%252cgr.%252fht ");
    this.Response.Write(this.Server.UrlDecode(str));

    输出:我是一段包含中文的文字!,fs.efe,gr./ht

    e Url编码的应用

    //页面跳转时,进行中文和标点的转换,在转换的页面中,可以通过Request.QueryString["aaa"] 直接转换回中文,但在地址栏是乱码
    this.Response.Redirect("11/22/33/Default5.aspx?aaa="+this.Server.UrlEncode("da,b中文jkc/kd,ef"));

    f  JS中escape编码 在转换的页面中,可以通过Request.QueryString["aaa"] 直接转换回中文,但在地址栏是乱码

    <input type="button" value="客户端编码" onclick="SetUrlEncoder();" />
    <script type="text/javascript">
    function SetUrlEncoder() {
    var txtText = document.getElementById("txtNum");
    var escapeText = escape(txtText.value);
    location = "11/22/33/Default5.aspx?aaa=" + escapeText;
    }
    </script>

    JS中escape编码请见: http://www.cnblogs.com/lmfeng/archive/2011/11/08/2240991.html

    2.其它

    Response.Write("你好," + this.txtName1.Text + "使用Response.End");
    HttpContext.Current.Response.End();//当输入有误或者其它等,用此句终止页面输出

  • 相关阅读:
    OSPF Configuration Examples
    enabling ip forwarding
    LeetCode 153. Find Minimum in Rotated Sorted Array
    洛谷 P1059 明明的随机数
    LeetCode 120. Triangle
    洛谷 P1047 校门外的树(待完善)
    C++万能头文件<bits/stdc++.h>的内容与优缺点
    LeetCode 217. Contains Duplicate
    LeetCode 414. Third Maximum Number
    洛谷 P1540 机器翻译
  • 原文地址:https://www.cnblogs.com/ChineseMoonGod/p/3729806.html
Copyright © 2011-2022 走看看