您的位置:首页 > 其它

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();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: