衣服=%D2%C2%B7%FE
get提交会这样怎么样直接调用函数
把 中文转换成 get提交之后的编码

解决方案 »

  1.   

    encodeURI和encodeURIComponent方法用于编码传递给浏览器的URI。其中encodeURI用于处理完整的URI(例如,http://top.csdn.net/javascript.html),encodeURIComponent用于处理URI的一个片段(例如,javascript.html)。
    主要区别是encodeURI()方法不对URI中特殊字符进行编码,如冒号、前斜杠、问号和英镑号,而encodeURIComponent()对所有非标准的字符进行编码。var sURI="http://top.csdn.net/javascript.html?ID=Mr SLin"
    alert(encodeURI(sURI));//http://top.csdn.net/javascript.html?ID=Mr%20SLin
    alert(encodeURIComponent(sURI));//http%3A%2F%2Ftop.csdn.net%2Fjavascript.html%3FID%3DMr%20SLin有时候会看到escapde()和unescape()用于编码和解码,但是它只能对ASCII进行正确编码,避免使用。
      

  2.   


    在后台用new String(request.getParameter(param).getBytes("utf-8"), "iso-8859-1");
    js传递参数需要编码后,提交用encodeURI(encodeURI(中文参数))
    or encodeURIComponent('中文参数');
    后台用URLDecoder.decode(request.getParameter("中文参数"), "utf-8")
      

  3.   

    补充下,至于为什么说encodeURIComponent()用于处理片段,从下面的代码来看它使得URI整个无效了,所以一般处理URI末尾的字符串。
    对应的解码函数是decodeURI()和decodeURIComponent(),用法一样。
      

  4.   

    我是想做个聚合搜索
    http://s.taobao.com/search?q=%D2%C2%B7%FE等于
    http://s.taobao.com/search?q=衣服http://youa.baidu.com/search/s?search_domain=1&category=&keyword=%D2%C2%B7%FE等于
    http://youa.baidu.com/search/s?search_domain=1&category=&keyword=衣服
    我需要直接提交过去需要搜索的值,
    我用的open方式打开页面
    没有用form提交
      

  5.   

    注意,不要在tomcat中设置url编码