JS encodeURI and Java urldecoder.decode

  • 2020-03-30 02:54:07
  • OfStack

If you don't want to see in the url is clear, such as http://localhost:8080/template_1/login.action? User = zhang SAN

Js encodeURI urldecoder.decode can be used together to encrypt the url

(1)JS data on the page var val = encodeURI(encodeURI(" to be sent to the server is a value ")); // call encodeURI twice

Href = "< % = basePath % > RecordManager/test_js_decodeURI. The action? Params = "+ val

(2) on the server side
 
HttpServletRequest request = ServletActionContext.getRequest(); 
String vString = request.getParameter("params"); 
System.out.println(" Transformation before :"+vString); 
String deString = URLDecoder.decode(vString, "UTF-8"); 
System.out.println(" After the transformation :"+deString); 

Utf-8 is consistent with the encoding on the page for example, pageEncoding=" utf-8 "on the JSP page and in this case utf-8

Right encoding on ie can be seen, if JSP pageEncoding=" utf-8 "right encoding on ie uncode(utf-8), if JSP pageEncoding="GBK", then right encoding on ie (simplified Chinese gb2312)

Related articles: