JS的encodeURI和java的URLDecoder.decode使用介绍
JS的encodeURI和java的URLDecoder.decode使用介绍
发布时间:2016-12-30 来源:查字典编辑
摘要:如果不想在url中看到有明文,比如http://localhost:8080/template_1/login.action?user=张三...

如果不想在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)

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新Javascript教程学习
热门Javascript教程学习
编程开发子分类