javascript url 相关函数(escape/encodeURL/encodeURIComponent区别)
完整的URL由这几个部分构成:scheme://host:port/path?query#fragment ,各部分的取法如下:
window.location.href:获取完整url的方法:,即scheme://host:port/path?query#fragment
window.location.protocol:获取rul协议scheme
window.location.host:获取host
window.location.port:获取端口号
window.location.pathname:获取url路径
window.location.search:获取参数query部分,注意此处返回的是?query
window.location.hash:获取锚点,#fragment
在js中可以使用escape(), encodeURL(), encodeURIComponent(),三种方法都有一些不会被编码的符号:
escape():@ * / +
encodeURL():! @ # $& * ( ) = : / ; ? + '
encodeURIComponent():! * ( ) '
在java端可以使用URLDecoder.decode(“中文”, "UTF-8");来进行解码
但是由于使用request.getParameter()来获取参数时已经对编码进行了一次解码,所以一般情况下只要在js中使用
encodeURIComponent("中文");
在java端直接使用request.getParameter()来获取即可返回中文。
如果你想在java端使用URLDecoder.decode(“中文”, "UTF-8");来解码也可以在js中进行二次编码,即:
encodeURIComponent(encodeURIComponent("中文"));
如果不进行二次编码的话,在java端通过decode方法取的会是乱码。
javascript url 相关函数(escape/encodeURL/encodeURIComponent区别)的更多相关文章
- JavaScript URL编码转换函数 encodeURIComponent()
encodeURIComponent()定义和用法 encodeURIComponent() 函数可把字符串作为 URI 组件进行编码. 语法:encodeURIComponent(URIstring ...
- escape encodeURI encodeURIComponent区别
escape() 函数可对字符串进行编码,这样就可以在所有的计算机上读取该字符串.使用unescape来解码. 有效的URI(统一资源标示符)是不能包含某些字符的,如空格,所以需要进行编码,编码方法有 ...
- escape(), encodeURL(), encodeURIComponent()
escape() 方法: 采用ISO Latin字符集对指定的字符串进行编码.所有的空格符.标点符号.特殊字符以及其他非ASCII字符都将被转化成%xx格式的字符编码(xx等于该字符在字符集表里面的编 ...
- JS 字符串编码函数(解决URL特殊字符传递问题):escape()、encodeURI()、encodeURIComponent()区别详解
javaScript中有三个可以对字符串编码的函数,分别是: escape,encodeURI,encodeURIComponent,相应3个解码函数:unescape,decodeURI,decod ...
- Url解码和编码 escape()、encodeURI()、encodeURIComponent()区别详解
Server.UrlDecode;解码 Server.UrlEncode;编码 url编码是一种浏览器用来打包表单输入的格式.浏览器从表单中获取所有的name和其中的值 ,将它们以name/value ...
- 【javascript】escape()、encodeURI()、encodeURIComponent()区别详解
JavaScript中有三个可以对字符串编码的函数,分别是: escape,encodeURI,encodeURIComponent,相应3个解码函数:unescape,decodeURI,decod ...
- javascript之url转义escape()、encodeURI()和encodeURIComponent()
JavaScript中有三个可以对字符串编码的函数,分别是: escape,encodeURI,encodeURIComponent,相应3个解码函数:unescape,decodeURI,decod ...
- escape()、encodeURI()、encodeURIComponent()区别详解--zt
JavaScript中有三个可以对字符串编码的函数,分别是: escape,encodeURI,encodeURIComponent,相应3个解码函数:unescape,decodeURI,decod ...
- JS转义 escape()、encodeURI()、encodeURIComponent()区别详解
JavaScript中有三个可以对字符串编码的函数,分别是: escape,encodeURI,encodeURIComponent,相应3个解码函数:unescape,decodeURI,decod ...
随机推荐
- 给linux添加一个回收站
http://blog.chinaunix.net/uid-26805356-id-3492419.html 都知道linux没有回收站,如果一不小心 rm -rf之后,很难恢复,所以就编写了一个回收 ...
- Linux系统入门学习:在CentOS上安装phpMyAdmin
问题:我正在CentOS上运行一个MySQL/MariaDB服务,并且我想要通过网络接口来用phpMyAdmin来管理数据库.在CentOS上安装phpMyAdmin的最佳方法是什么? phpMyAd ...
- hdu 2665 Kth number
划分树 /* HDU 2665 Kth number 划分树 */ #include<stdio.h> #include<iostream> #include<strin ...
- List-ApI及详解
1.API : add(Object o) remove(Object o) clear() indexOf(Object o) get(int i) size() iterator() isEmpt ...
- 【转】beancopy的替代方案
链接:http://jingyan.baidu.com/article/215817f7d55b871edb14235b.html 最近在项目中接触到了BeanUtils.copyProperties ...
- 回调函数的实现 & 结构体的继承
------------------------------------------------------------------------------------[1]------------- ...
- A Gentle Introduction to the Gradient Boosting Algorithm for Machine Learning
A Gentle Introduction to the Gradient Boosting Algorithm for Machine Learning by Jason Brownlee on S ...
- 论文笔记之:MatchNet: Unifying Feature and Metric Learning for Patch-Based Matching
MatchNet: Unifying Feature and Metric Learning for Patch-Based Matching CVPR 2015 本来都写到一半了,突然笔记本死机了 ...
- caffe: test code for PETA dataset
test code for PETA datasets .... #ifdef WITH_PYTHON_LAYER #include "boost/python.hpp" name ...
- Top Things to Consider When Troubleshooting Complex Application Issues
http://blogs.msdn.com/b/debuggingtoolbox/archive/2011/10/03/top-things-to-consider-when-troubleshoot ...