JavaScript 代码encode
functionfindNE(){ var nd = document.getElementById("NE").value; nd = encodeURIComponent(encodeURIComponent(nd)); alert(nd); $.fn.zTree.destroy("netree"); setting.async.url="common/getNeList.action?seachName="+nd; $.fn.zTree.init($("#netree"), setting); }
encodeURI 和 encodeURIComponent 的写法一致
java代码decode
String serchName = request.getParameter("seachName"); System.out.println("serchName1::::::::::::::::::::::"+serchName); if(StringUtils.isNotBlank(serchName)){ try{ serchName = java.net.URLDecoder.decode(serchName,"UTF-8"); }catch (UnsupportedEncodingException e) { e.printStackTrace(); } } System.out.println("serchName2::::::::::::::::::::::"+serchName);
注意:URLDecoder.decode 方法中需要指名编码格式为 UTF-8,不然会存在编码乱码问题。