zoukankan      html  css  js  c++  java
  • java、js的编码、解码

    如果在地址栏挂载参数,特别是包含中文,往往要进行编码,取值时再解码,以下是java和js中编码、解码的各自方法。

    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方法进行解码。

  • 相关阅读:
    jquery ajax
    js 列表选择
    Jquery 搜索框自动提示
    图片居中跟inline-block
    模式学习(一)
    高效图形(一)
    eval() / Function()
    css3(一)
    回调函数(二)
    回调函数(一)
  • 原文地址:https://www.cnblogs.com/wql025/p/4979634.html
Copyright © 2011-2022 走看看