encodeURIComponent()与encodeURI()
来源:互联网 发布:linux如何安装vim 编辑:程序博客网 时间:2024/06/05 14:45
encodeURIComponent() 函数可把字符串作为 URI 组件进行编码。
encodeURIComponent(URIstring)
该方法不会对 ASCII 字母和数字进行编码,也不会对这些 ASCII 标点符号进行编码: - _ . ! ~ * ' ( ) 。
encodeURI() 函数可把字符串作为 URI 进行编码。
encodeURI(URIstring)
该方法的目的是对 URI 进行完整的编码,因此对以下在 URI 中具有特殊含义的 ASCII 标点符号,encodeURI() 函数是不会进行转义的:;/?:@&=+$,#
encodeURIComponent() 函数 与 encodeURI() 函数的区别之处:
前者假定它的参数是 URI 的一部分(比如协议、主机名、路径或查询字符串).
要连续两次调用 encodeURI(String) 方法
是因为 Java 中的 request.getParameter(String) 方法会进行一次 URI 的解码过程,调用时内置的解码过程会导致乱码出现。
而 URI 编码两次后, request.getParameter(String) 函数得到的是原信息 URI 编码一次的内容。
接着用 java.net.URLDecoder.decode(String str,String codename) 方法,将已经编码的 URI 转换成原文。
- comment=encodeURIComponent("http://cang.baidu.com/bruce42");
- var pdata="method=updateComment&date="+dateStr+"&comment="+comment;
- pdata=encodeURI(encodeURI(pdata));
comment=encodeURIComponent("http://cang.baidu.com/bruce42");var pdata="method=updateComment&date="+dateStr+"&comment="+comment;pdata=encodeURI(encodeURI(pdata));
- //BookingDaysCommentForm.java
- public void setComment(String comment) {
- try {
- this.comment = java.net.URLDecoder.decode(comment,"utf-8");
- } catch (UnsupportedEncodingException e) {
- // TODO Auto-generated catch block
- this.comment = comment;
- LOGGER.error("Decode comment error:"+e.getMessage());
- }catch (RuntimeException re){
- this.comment = comment;
- LOGGER.error("Decode comment RuntimeException:"+re.getMessage());
- }
- }
//BookingDaysCommentForm.javapublic void setComment(String comment) {try {this.comment = java.net.URLDecoder.decode(comment,"utf-8");} catch (UnsupportedEncodingException e) {// TODO Auto-generated catch blockthis.comment = comment;LOGGER.error("Decode comment error:"+e.getMessage());}catch (RuntimeException re){this.comment = comment;LOGGER.error("Decode comment RuntimeException:"+re.getMessage());} }
- //BookingDaysCommentOpenAction.java
- String formatComment = formBean.getComment();
- formatComment = java.net.URLDecoder.decode(formatComment,"utf-8");
后台编码时候 前台空格变成+ 处理方式:
java.net.URLEncoder.encode("测试","UTF-8").replace("+", "%20");
前台 decodeURI(str)
- encodeURI 与 encodeURIComponent()
- encodeURIComponent()与encodeURI()
- encodeURI与encodeURIComponent
- escape,encodeURI与encodeURIComponent
- encodeURI与encodeURIComponent的区别
- 编码与安全encodeURI,encodeURIComponent
- encodeURI与encodeURIComponent方法的区别
- ajax中文编码问题--encodeURIComponent() 与encodeURI()
- encodeURIComponent与encodeURI 解决乱码等。。
- JS escape、encodeURI 、encodeURIComponent 编码与解码
- encodeURI与encodeURIComponent的用法区别
- encodeURI、decodeURI、encodeURIComponent与decodeURIComponent的区别
- 【开发笔记】JS中encodeURI与encodeURIComponent
- encodeURI与encodeURIComponent方法的区别
- JS的 escape、encodeURI 、encodeURIComponent 编码与解码
- 谈谈encodeURI和encodeURIComponent以及escape的区别与应用
- 谈谈encodeURI和encodeURIComponent以及escape的区别与应用
- escape encodeURI 和encodeURIComponent
- 一个sed 反转字符串
- IBM X3650 M3 服务器安装linux找不到磁盘的解决办法
- 如何提高代码质量(管理篇):代码复查
- RGB彩色空间的不同转换公式
- SVN 命令行基本用法
- encodeURIComponent()与encodeURI()
- 浅谈Java中的几种随机数
- jQuery阻止冒泡和HTML默认操作
- 解决ASP.NET中的各种乱码问题
- 浅谈 Flash/Flex/HTML5 技术选型
- ActiveX 和NPAPI 插件点击CEdit 弹出软键盘
- 不要成为工具的奴隶
- C语言的宏定义 模拟 RTTI
- oracle的rollup