strcpy、memcpy和memmove的区别和实现
2016-01-19 01:08
323 查看
转的,已经无法考证原作者。
js对文字进行编码涉及3个函数:escape,encodeURI,encodeURIComponent,相应3个解码函数:unescape,decodeURI,decodeURIComponent
1、 传递参数时需要使用encodeURIComponent,这样组合的url才不会被#等特殊字符截断。
例如:<script language="javascript">document.write('<a href="http://passport.baidu.com/?logout&aid=7&u= +encodeURIComponent("http://cang.baidu.com/bruce42")+">退出</a>');</script>
2、 进行url跳转时可以整体使用encodeURI
例如:Location.href=encodeURI("http://cang.baidu.com/do/s?word=百度&ct=21");
3、 js使用数据时可以使用escape
例如:搜藏中history纪录。
4、 escape对0-255以外的unicode值进行编码时输出%u****格式,其它情况下escape,encodeURI,encodeURIComponent编码结果相同。
最多使用的应为encodeURIComponent,它是将中文、韩文等特殊字符转换成utf-8格式的url编码,所以如果给后台传递参数需要使用encodeURIComponent时需要后台解码对utf-8支持(form中的编码方式和当前页面编码方式相同)
escape不编码字符有69个:*,+,-,.,/,@,_,0-9,a-z,A-Z
encodeURI不编码字符有82个:!,#,$,&,',(,),*,+,,,-,.,/,:,;,=,?,@,_,~,0-9,a-z,A-Z
encodeURIComponent不编码字符有71个:!, ',(,),*,-,.,_,~,0-9,a-z,A-Z
(转http://xieye.iteye.com/blog/77768)关于乱码的处理之特别心得
工作中,因为碰到ajax乱码问题,终于想出一个够绝的办法,
问题是:从客户端用ajax对象传数据到服务器段出现乱码,服务端的程序有过滤器,会自己进行一些处理,我也不知道怎么处理的,总之汉字就是显示乱码,
应对办法,javascript有一个encodeURIComponent
方法,java也有对应方法在java.net包中
对要传送的参数编码两次,在java中解码一次就OK,此办法只针对用正常办法解决不了的问题,属于歪招。
客户端代码:
function test11(){
createXMLHttp();
xmlHttp.onreadystatechange = handleState;
var han = "汉字 s";
var url = "/portal/event/fwczh/testAjax";
var han3 = encodeURIComponent(encodeURIComponent(han)); //这句话重要
url += "?a="+han3;
xmlHttp.open("GET",url,true);
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlHttp.send(null);
}
var xmlHttp;
function createXMLHttp(){
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
function handleState(){
if(xmlHttp.readyState == 4){
if(xmlHttp.status == 200){
alert(xmlHttp.responseText);
}
}
}
服务端代码:
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Cache-Control", "no-store");
response.setDateHeader("Expires", 0);
response.setHeader("Pragma", "no-cache");
//out.clear();
String sss = request.getParameter("a");
System.out.print("转变前:"+sss);
String b = URLDecoder.decode(sss,"UTF-8");//这句话重要
System.out.print("转变后:"+b);
out.print(b);
out.close();
js对文字进行编码涉及3个函数:escape,encodeURI,encodeURIComponent,相应3个解码函数:unescape,decodeURI,decodeURIComponent
1、 传递参数时需要使用encodeURIComponent,这样组合的url才不会被#等特殊字符截断。
例如:<script language="javascript">document.write('<a href="http://passport.baidu.com/?logout&aid=7&u= +encodeURIComponent("http://cang.baidu.com/bruce42")+">退出</a>');</script>
2、 进行url跳转时可以整体使用encodeURI
例如:Location.href=encodeURI("http://cang.baidu.com/do/s?word=百度&ct=21");
3、 js使用数据时可以使用escape
例如:搜藏中history纪录。
4、 escape对0-255以外的unicode值进行编码时输出%u****格式,其它情况下escape,encodeURI,encodeURIComponent编码结果相同。
最多使用的应为encodeURIComponent,它是将中文、韩文等特殊字符转换成utf-8格式的url编码,所以如果给后台传递参数需要使用encodeURIComponent时需要后台解码对utf-8支持(form中的编码方式和当前页面编码方式相同)
escape不编码字符有69个:*,+,-,.,/,@,_,0-9,a-z,A-Z
encodeURI不编码字符有82个:!,#,$,&,',(,),*,+,,,-,.,/,:,;,=,?,@,_,~,0-9,a-z,A-Z
encodeURIComponent不编码字符有71个:!, ',(,),*,-,.,_,~,0-9,a-z,A-Z
(转http://xieye.iteye.com/blog/77768)关于乱码的处理之特别心得
工作中,因为碰到ajax乱码问题,终于想出一个够绝的办法,
问题是:从客户端用ajax对象传数据到服务器段出现乱码,服务端的程序有过滤器,会自己进行一些处理,我也不知道怎么处理的,总之汉字就是显示乱码,
应对办法,javascript有一个encodeURIComponent
方法,java也有对应方法在java.net包中
对要传送的参数编码两次,在java中解码一次就OK,此办法只针对用正常办法解决不了的问题,属于歪招。
客户端代码:
function test11(){
createXMLHttp();
xmlHttp.onreadystatechange = handleState;
var han = "汉字 s";
var url = "/portal/event/fwczh/testAjax";
var han3 = encodeURIComponent(encodeURIComponent(han)); //这句话重要
url += "?a="+han3;
xmlHttp.open("GET",url,true);
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlHttp.send(null);
}
var xmlHttp;
function createXMLHttp(){
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
function handleState(){
if(xmlHttp.readyState == 4){
if(xmlHttp.status == 200){
alert(xmlHttp.responseText);
}
}
}
服务端代码:
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Cache-Control", "no-store");
response.setDateHeader("Expires", 0);
response.setHeader("Pragma", "no-cache");
//out.clear();
String sss = request.getParameter("a");
System.out.print("转变前:"+sss);
String b = URLDecoder.decode(sss,"UTF-8");//这句话重要
System.out.print("转变后:"+b);
out.print(b);
out.close();
相关文章推荐
- 关于HibernateGenericDAO 的一点补充
- 动态规划-最大子矩阵和
- uva 10929 - You can say 11
- (一二一)第十章复习题
- Substring with Concatenation of All Words
- javascript捕获键盘组合事件
- (一二〇)抽象数据类型
- 疾病尚需用猛药
- 【C语言】冒泡排序及优化
- (一一九)类作用域
- 学习java的道路
- (一一八)对象数组
- hypervisor on vehicle
- 设计模式之代理模式(二结构型)
- (一一七)this指针
- http servlet服务器和android客户端(二)第一个android客户端
- 单例模式的应用
- 进程间通信(IPC) 之 共享内存 和 闲扯其他一些东西
- python3 crontab 下运行python输出中文失败
- MonoBehaviour继承类及其重要方法