您的位置:首页 > 编程语言 > Java开发

java中URLEncoder、URLDecoder 与js中 en/decodeURI()、en/decodeURIComponent()使用

2017-02-06 18:48 555 查看
1、java中URLEncoder、URLDecoder:http://tech.sina.com.cn/s/2008-07-07/1053722241.shtml

js中decodeURI()、decodeURIComponent():http://www.cnblogs.com/Erik_Xu/articles/2305011.html

java:

URLEncoder.encode(res, "UTF-8").replace("+","%20");

如果res为 空(" "),则需要将+替换为%20,否则在js中进行解码的时候无法对加好(+)进行正确的解码

使用事例:

java:

String dd = URLEncoder.encode(res, "UTF-8").replace("+","%20");//编码

js:

String ddd = decodeURIComponent(dd);或者String ddd = decodeURI(dd);//解码

2、en/decodeURI()、en/decodeURIComponent()区别:

结果:

明显看出 ,使用encodeURI : 和 //  没有被编码,而encodeURIComponent编码了 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: