Home > Web Front-end > JS Tutorial > body text

Introduction to the use of JS's encodeURI and java's URLDecoder.decode_javascript skills

WBOY
Release: 2016-05-16 16:49:23
Original
1206 people have browsed it

If you don’t want to see clear text in the url, such as http://localhost:8080/template_1/login.action?user=张三

, you can use js’s encodeURI and URLDecoder.decode together to decode the url. Under encryption

(1) JS puts the data on the page var val = encodeURI(encodeURI("The value to be transmitted to the server is the value")); //Call encodeURI 2 times

href= "<%=basePath%>recordManager/test_js_decodeURI.action?params=" val

(2) Server side like this

Copy code The code is as follows:

HttpServletRequest request = ServletActionContext.getRequest();
String vString = request.getParameter("params");
System.out. println("Before conversion:" vString);
String deString = URLDecoder.decode(vString, "UTF-8");
System.out.println("After conversion:" deString);

UTF-8 is consistent with the encoding on the page. For example: pageEncoding="UTF-8" on the jsp page, here is UTF-8

You can see it by right-clicking on the encoding on IE. If pageEncoding="UTF-8" on jsp, the right-click encoding on ie is uncode (UTF-8), if pageEncoding="GBK" on jsp, then the right-click encoding on ie (simplified Chinese gb2312)
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!