码迷,mamicode.com
首页 > Web开发 > 详细

web编码

时间:2014-05-15 18:07:30      阅读:343      评论:0      收藏:0      [点我收藏+]

标签:blog   code   java   c   ext   http   

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

web编码,布布扣,bubuko.com

web编码

标签:blog   code   java   c   ext   http   

原文地址:http://www.cnblogs.com/ChineseMoonGod/p/3729806.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!