JS encodeURI and Java Urldecoder.decode use introduction _javascript tips

Source: Internet
Author: User
If you do not want to see a clear text in the URL, such as http://localhost:8080/template_1/login.action?user= John

You can use JS's encodeURI Urldecoder.decode to use together to encrypt the URL

(1) JS on the page to the data var val = encodeURI (encodeURI ("to upload to the server side is the value")); Call 2 times encodeURI

href= "<%=basepath%>recordmanager/test_js_decodeuri.action?params=" +val

(2) server-side such
Copy Code code 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 code on the page. For example: pageencoding= "UTF-8" on the JSP page it's going to be UTF-8.

In IE right key code can see, if the JSP on pageencoding= "UTF-8" ie on the right key code Uncode (UTF-8), if the JSP pageencoding= "GBK", then IE on the right key code (Simplified Chinese gb2312)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.