- 浏览: 801529 次
- 性别:
- 来自: 淄博
文章分类
- 全部博客 (250)
- Hibernate (29)
- FCKEditor (5)
- Jstl (6)
- JavaScript (33)
- 异常备忘 (49)
- Mysql (1)
- XP小技巧 (8)
- Java基础 (48)
- Freemarker (6)
- Birt (5)
- SQL (22)
- Spring (13)
- XHTML+CSS (7)
- Struts (5)
- ExtJs (13)
- Tomcat (7)
- JFreeChart (1)
- Json-Lib (0)
- Jquery&EasyUI (22)
- MyEclipse (4)
- Firefox (1)
- Apache Shiro (1)
- Oracle (5)
- Spring Security (2)
- SQLServer (6)
- Bootstrap (1)
- POI (2)
- SpringMVC (4)
最新评论
-
xinglianxlxl:
对我有用,谢谢
Spring 定时任务之 @Scheduled cron表达式 -
cb_2017:
...
Spring 定时任务之 @Scheduled cron表达式 -
a251628111:
谢谢分享
Spring 定时任务之 @Scheduled cron表达式 -
hl174:
确实是这个问题 不知道谁把数据库改了
java.lang.IllegalArgumentException: Timestamp format must be yyyy-mm-dd hh:mm:ss -
gotosuzhou:
zhangzi 写道lylshr 写道顶,大哥你真强啊晕死,这 ...
数据库是SQLServer2008,出现'limit' 附近有语法错误
摘抄自:http://www.cnblogs.com/bluewind2879/archive/2009/02/15/1390864.html
在使用url进行参数传递时,经常会传递一些中文名的参数或URL地址,在后台处理时会发生转换错误。在有些传递页面使用GB2312,而在接收页面使用UTF8,这样接收到的参数就可能会与原来发生不一致。使用服务器端的urlEncode函数编码的URL,与使用客户端javascript的encodeURI函数编码的URL,结果就不一样。
javaScript中的编码方法:
escape() 方法:
采用ISO Latin字符集对指定的字符串进行编码。所有的空格符、标点符号、特殊字符以及其他非ASCII字符都将被转化成%xx格式的字符编码(xx等于该字符在字符集表里面的编码的16进制数字)。比如,空格符对应的编码是%20。unescape方法与此相反。不会被此方法编码的字符: @ * / +
英文解释:MSDN JScript Reference: The escape method returns a string value (in Unicode format) that contains the contents of [the argument]. All spaces, punctuation, accented characters, and any other non-ASCII characters are replaced with %xx encoding, where xx is equivalent to the hexadecimal number representing the character. For example, a space is returned as "%20."
Edge Core Javascript Guide: The escape and unescape functions let you encode and decode strings. The escape function returns the hexadecimal encoding of an argument in the ISO Latin character set. The unescape function returns the ASCII string for the specified hexadecimal encoding value.
encodeURI() 方法:
采用ISO Latin字符集对指定的字符串进行编码。所有的空格符、标点符号、特殊字符以及其他非ASCII字符都将被转化成%xx格式的字符编码(xx等于该字符在字符集表里面的编码的16进制数字)。比如,空格符对应的编码是%20。unescape方法与此相反。不会被此方法编码的字符: @ * / +
英文解释:MSDN JScript Reference: The escape method returns a string value (in Unicode format) that contains the contents of [the argument]. All spaces, punctuation, accented characters, and any other non-ASCII characters are replaced with %xx encoding, where xx is equivalent to the hexadecimal number representing the character. For example, a space is returned as "%20."
Edge Core Javascript Guide: The escape and unescape functions let you encode and decode strings. The escape function returns the hexadecimal encoding of an argument in the ISO Latin character set. The unescape function returns the ASCII string for the specified hexadecimal encoding value.
encodeURI() 方法:
把URI字符串采用UTF-8编码格式转化成escape格式的字符串。不会被此方法编码的字符:! @ # $& * ( ) = : / ; ? + '
英文解释:MSDN JScript Reference: The encodeURI method returns an encoded URI. If you pass the result to decodeURI, the original string is returned. The encodeURI method does not encode the following characters: ":", "/", ";", and "?". Use encodeURIComponent to encode these characters. Edge Core Javascript Guide: Encodes a Uniform Resource Identifier (URI) by replacing each instance of certain characters by one, two, or three escape sequences representing the UTF-8 encoding of the character
encodeURIComponent() 方法:
英文解释:MSDN JScript Reference: The encodeURI method returns an encoded URI. If you pass the result to decodeURI, the original string is returned. The encodeURI method does not encode the following characters: ":", "/", ";", and "?". Use encodeURIComponent to encode these characters. Edge Core Javascript Guide: Encodes a Uniform Resource Identifier (URI) by replacing each instance of certain characters by one, two, or three escape sequences representing the UTF-8 encoding of the character
encodeURIComponent() 方法:
把URI字符串采用UTF-8编码格式转化成escape格式的字符串。与encodeURI()相比,这个方法将对更多的字符进行编码,比如 / 等字符。所以如果字符串里面包含了URI的几个部分的话,不能用这个方法来进行编码,否则 / 字符被编码之后URL将显示错误。不会被此方法编码的字符:! * ( )
英文解释:MSDN JScript Reference: The encodeURIComponent method returns an encoded URI. If you pass the result to decodeURIComponent, the original string is returned. Because the encodeURIComponent method encodes all characters, be careful if the string represents a path such as /folder1/folder2/default.html. The slash characters will be encoded and will not be valid if sent as a request to a web server. Use the encodeURI method if the string contains more than a single URI component. Mozilla Developer Core Javascript Guide: Encodes a Uniform Resource Identifier (URI) component by replacing each instance of certain characters by one, two, or three escape sequences representing the UTF-8 encoding of the character.
英文解释:MSDN JScript Reference: The encodeURIComponent method returns an encoded URI. If you pass the result to decodeURIComponent, the original string is returned. Because the encodeURIComponent method encodes all characters, be careful if the string represents a path such as /folder1/folder2/default.html. The slash characters will be encoded and will not be valid if sent as a request to a web server. Use the encodeURI method if the string contains more than a single URI component. Mozilla Developer Core Javascript Guide: Encodes a Uniform Resource Identifier (URI) component by replacing each instance of certain characters by one, two, or three escape sequences representing the UTF-8 encoding of the character.
因此,对于中文字符串来说,如果不希望把字符串编码格式转化成UTF-8格式的(比如原页面和目标页面的charset是一致的时候),只需要使用escape。如果你的页面是GB2312或者其他的编码,而接受参数的页面是UTF-8编码的,就要采用encodeURI或者encodeURIComponent。
另外,encodeURI/encodeURIComponent是在javascript1.5之后引进的,escape则在javascript1.0版本就有。
英文注释:The escape() method does not encode the + character which is interpreted as a space on the server side as well as generated by forms with spaces in their fields. Due to this shortcoming, you should avoid use of escape() whenever possible. The best alternative is usually encodeURIComponent().Use of the encodeURI() method is a bit more specialized than escape() in that it encodes for URIs [REF] as opposed to the querystring, which is part of a URL. Use this method when you need to encode a string to be used for any resource that uses URIs and needs certain characters to remain un-encoded. Note that this method does not encode the ' character, as it is a valid character within URIs.Lastly, the encodeURIComponent() method should be used in most cases when encoding a single component of a URI. This method will encode certain chars that would normally be recognized as special chars for URIs so that many components may be included. Note that this method does not encode the ' character, as it is a valid character within URIs.
发表评论
-
Java、Javascript去掉字符串全面的0
2019-03-08 10:22 563//Java 结果:1230 String str = & ... -
TypeError: n[m] is undefined
2017-11-11 11:49 725TypeError: n[m] is undefined ... -
SpringMVC提交带文件上传的form表单报错
2017-11-09 11:25 574java.lang.ClassCastException: ... -
正则表达式-三位数字
2017-08-14 17:19 1337<input type="text" ... -
js 实现两个数组(一个数组包含于另一个数组中)去重的问题
2017-07-26 15:37 928var arr1 = [ {id:1,na ... -
jquery radio选中和不选中
2016-12-09 17:14 818//选中 $("#xxx").attr ... -
Jquery DataTables 自定义布局
2016-12-08 09:29 691Jquery DataTables 自定义布局 ... -
dataTables自增序号转载地址
2016-12-07 08:11 1170"fnDrawCallback": fu ... -
easyui-datagrid 翻页数据不变
2016-06-08 10:31 707easyui-datagrid 翻页数据不变原因之一:属性s ... -
document.body is null
2015-09-10 08:55 950虽然body是JS中的DOM技术中所有浏览器支持的属性,但在 ... -
js页面跳转和js对iframe进行页面跳转、刷新
2015-07-24 14:29 978js页面跳转和js对iframe进行页面跳转、刷新 ... -
JQuery设置checkbox复选框,attr不可行,prop才是正确答案
2015-01-09 15:20 3429//判断checkbox是否被选中 if($(this). ... -
JS正则判断身份证合法化
2014-04-23 10:31 1063//这个可以验证15位和18位的身份证,并且包含生日 ... -
ajaxfileupload以JSON为返回数据类型出现的因符号无法解析的错误的解决方案
2014-01-06 16:12 1395转载地址:http://blog.csdn.net/dugu ... -
IE6 超链接的onclick事件无效的解决方法
2013-07-25 09:12 963<a style="color:#487D ... -
IFRAME中获取及改变父窗口元素(兼容FIREFOX)
2013-03-02 15:02 2945主页面ifmain.htm: <table wid ... -
使用jQuery或JavaScript 加载 css 文件
2012-12-14 16:02 1088有时我们可能会需要使用 jQuery 来加载一个外部的 c ... -
jquery load 跨域插件
2012-10-18 10:49 1442<script type="text/java ... -
JavaScript去除字符串两边空格
2012-09-26 16:06 1106去除字符串左右两端的空格,在大部分编程语言中,比如PHP、vb ... -
JS获取本日、本月、本季度、本年日期
2012-03-16 07:40 2341var now = new Date(); ...
相关推荐
- 使用`encodeURIComponent`,`query`参数会被编码为`javascript%20%E7%BC%96%E7%A0%81`,这里的空格被正确地转换为%20,适合在URL中使用。 在实际编程中,`encodeURIComponent`通常是最常用的,因为它能确保所有非...
综上所述,尽管 `escape()`、`encodeURI()` 和 `encodeURIComponent()` 都是用来编码字符串的函数,但它们的应用场景和编码规则是不同的。选择合适的函数能够帮助我们在网络传输中确保数据的安全性和准确性。
为了解决这一问题,JavaScript提供了几种不同的编码方法来处理URL中的特殊字符。本文将详细介绍`escape()`, `encodeURI()`, `encodeURIComponent()`这三个函数的功能、使用场景以及它们之间的区别。 #### 一、`...
在JavaScript中,`escape()`, `encodeURI()`, 和 `encodeURIComponent()` 是三个常见的字符串编码函数,它们各自有独特的用途和特点。理解它们的区别对于编写健壮的JavaScript代码至关重要。 首先,`escape()` 函数...
JavaScript 中对 URL 编码和解码涉及到六个函数:escape、encodeURI、encodeURIComponent、unescape、decodeURI 和 decodeURIComponent。这六个函数的使用场景和特点分别是: escape 函数:escape 函数用于将字符串...
在JavaScript中,`escape()`, `encodeURI()`, 和 `encodeURIComponent()` 是三个常见的字符串编码函数,它们用于处理和转换字符串中的特殊字符。虽然它们都与字符串编码有关,但各自的作用和适用场景有所不同。 ...
在JavaScript中,`encodeURI()`、`encodeURIComponent()`和`escape()`是三个用于字符串编码的函数,它们的主要目的是确保特殊字符在传输过程中不会引起错误。理解它们之间的差异对于编写正确处理URL和数据的...
JavaScript中的字符串编码转换是开发过程中不可或缺的一部分,尤其是在处理URL、查询参数或特殊字符时。本文将详细介绍`escape()`、`encodeURI()`和`encodeURIComponent()`这三个函数,并解释它们的区别和使用场景。...
在某些场景下,如编码URL中的参数,`encodeURIComponent`是最佳选择,因为它可以确保每个参数都安全地包含在URL中。 具体应用场景如下: 1. 如果你需要对一个与URL无关的普通字符串进行编码,`escape`是合适的选择...
而他们之间的异同却困扰了很多的Javascript初学者,这篇文章详细的给大家介绍了js中编码函数:escape,encodeURI与encodeURIComponent的相关资料,需要的朋友可以参考下。
- **二次转码**:先使用`encodeURI()` 编码一次,再用`encodeURIComponent()` 编码一次,这样URL中的特殊字符都会被编码。在服务器端,使用`URLDecoder.decode(name, "UTF-8")` 进行解码。 2. **Java服务器端处理*...
JavaScript中的字符串编码函数主要包括`escape()`、`encodeURI()`和`encodeURIComponent()`,它们的作用是对字符串进行编码处理,以便在网络中安全地传输数据。这三种函数都有对应的解码函数:`unescape()`、`...
encodeURI和encodeURIComponet函数都是javascript中用来对URI进行编码,将相关参数转换成UTF-8编码格式的数据。URI在进行定位跳转时,参数里面的中文、日文等非ASCII编码都会进行编码转换
2. encodeURI()是javascript中真正用来对URL编码的函数。编码整个URL地址,但对特殊含义的符号”;/?:@&=+$,#”,也不进行编码。对应的解码函数是decodeURI()。 3. encodeURIComponent()能编码”;/?:@&=+$,#”这些...