java、js的编码、解码
2015-11-20 02:05
435 查看
如果在地址栏挂载参数,特别是包含中文,往往要进行编码,取值时再解码,以下是java和js中编码、解码的各自方法。
java:
可以看到先是用URLEncoder.encode对中文“我”进行编码,在用URLDecoder.decode方法进行解码。
js:
在js中,先用encodeURIComponent方法对中文“我”进行编码,在用encodeURIComponent方法进行解码。
java:
@Test public void test3() throws UnsupportedEncodingException{ System.out.println(URLEncoder.encode("我", "UTF-8"));//%E6%88%91 System.out.println(URLDecoder.decode("%E6%88%91", "UTF-8") );//我 }
可以看到先是用URLEncoder.encode对中文“我”进行编码,在用URLDecoder.decode方法进行解码。
js:
alert(encodeURIComponent('我'))//"%E6%88%91" alert(decodeURIComponent(encodeURIComponent('我')) )//我
在js中,先用encodeURIComponent方法对中文“我”进行编码,在用encodeURIComponent方法进行解码。
相关文章推荐
- PHP在eclipse上的调试
- 从github上下载项目到eclipse中
- 关于spring的context:component-scan
- Java中的泛型
- Java源程序的编译及执行问题
- Java 数组Array 转换为 List
- 在servlet中用spring @Autowire 注入.
- Java事件机制
- WEBjava开发日记(1)
- java正则表达式筛选字符串中的ip
- java中String的常用方法
- 10018---JavaWeb基础--过滤器(Filter)
- JAVA中怎样把用户输入的字符串存入数组中?
- Java数组的基本操作
- java.lang.OutOfMemoryError: Java heap space解决方法
- 异常:pointerIndex out of range
- OpenProj打开不了或者提示"Failed to load Java VM Library"的错误的解决方案
- Spring Security(01)——初体验
- Java PinBall 简单弹球小游戏【4】碰撞检测及边界检测
- Spring mvc 中使用 kaptcha 验证码