如果不想在url中看到有明文可以使用js的encodeURI的URLDecoder.decode一起使用一起来把url加密下,下面有个不错的示例,大家不妨参考下
如果不想在url中看到有明文,比如http://localhost:8080/template_1/login.action?user=张三
可以使用js的encodeURI的URLDecoder.decode一起使用一起来把url加密下
(1)JS在页面上把数据var val = encodeURI(encodeURI("要传到服务器端的是值")); //调用2次encodeURI
href="<%=basePath%>recordManager/test_js_decodeURI.action?params="+val
(2)服务器端这样
HttpServletRequest request = ServletActionContext.getRequest();
String vString = request.getParameter("params");
System.out.println("转换前:"+vString);
String deString = URLDecoder.decode(vString, "UTF-8");
System.out.println("转换后:"+deString);
UTF-8是和页面上的编码保持一致 比如:jsp页面上 pageEncoding="UTF-8" 这里就要是UTF-8
在ie上右键编码就能看到,如果jsp上pageEncoding="UTF-8" ie上右键编码uncode(UTF-8),如果jsp上pageEncoding="GBK",那么 ie上右键编码(简体中文gb2312)
可以使用js的encodeURI的URLDecoder.decode一起使用一起来把url加密下
(1)JS在页面上把数据var val = encodeURI(encodeURI("要传到服务器端的是值")); //调用2次encodeURI
href="<%=basePath%>recordManager/test_js_decodeURI.action?params="+val
(2)服务器端这样
复制代码代码如下:
HttpServletRequest request = ServletActionContext.getRequest();
String vString = request.getParameter("params");
System.out.println("转换前:"+vString);
String deString = URLDecoder.decode(vString, "UTF-8");
System.out.println("转换后:"+deString);
UTF-8是和页面上的编码保持一致 比如:jsp页面上 pageEncoding="UTF-8" 这里就要是UTF-8
在ie上右键编码就能看到,如果jsp上pageEncoding="UTF-8" ie上右键编码uncode(UTF-8),如果jsp上pageEncoding="GBK",那么 ie上右键编码(简体中文gb2312)
本文介绍如何利用JavaScript的encodeURI方法与Java的URLDecoder.decode方法结合使用来加密URL参数,防止敏感信息在URL中直接显示。示例展示了客户端如何进行双重编码以及服务器端如何解码。
6593

被折叠的 条评论
为什么被折叠?



