• 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();//当输入有误或者其它等,用此句终止页面输出

  • 相关阅读:
    单元测试,集成测试与系统测试
    关于 单窗口服务模型模拟 进行的小测试
    软件测试新随笔
    白盒测试
    黑盒测试小实验
    JUnit框架初次体验
    等价类划分进阶篇
    等价类划分
    因果图法测试小例
    android中将EditText改成不可编辑的状态
  • 原文地址:https://www.cnblogs.com/ChineseMoonGod/p/3729806.html
Copyright © 2020-2023  润新知