A few days ago encountered the issue of URL special character encoding, here to tidy up:
Javascript
1. Encoding Escape (String)
Some of these characters are replaced with 16-binary escape sequences.
Decode Unescape (String)
This function works by finding a sequence of characters in the form%xx and%uxxxx (x for hexadecimal digits), decoding with Unicode characters \U00XX and \uxxxx replacing such sequences of characters.
* Note: ECMAScript v3 against using this method, the app uses decodeURI () and decodeuricomponent () to replace it.
2. Code encodeURI (uristring)
Return value: A copy of uristring, where some of the characters will be replaced by a hexadecimal escape sequence.
* If the URI component contains delimiters, for example? and #, each component should be encoded using the encodeURIComponent () method.
Decoding decodeURI (uristring)
Return value: A copy of uristring, where the hexadecimal escape sequence is replaced by the character they represent.
3. Code encodeURIComponent (uristring)
Return value: A copy of uristring, where some of the characters will be replaced by a hexadecimal escape sequence.
Decoding decodeURIComponent (uristring)
Return value: A copy of uristring, where the hexadecimal escape sequence is replaced by the character they represent.
* encodeURIComponent () differs from encodeURI ()
encodeURIComponent (uristring): Assuming that its arguments are part of a URI (such as a protocol, hostname, path, or query string), the encodeURIComponent () function escapes the URI used to delimit Punctuation marks (?) for each part. # etc).
encodeURI (uristring): does not encode delimiters in URIs, such as? such as
Java
Code: Class Urlencoder
Static string Encode (string s); static string encode (string s, String enc); // ENC encoding recommended use UTF-8
Decoding: Class Urldecoder
Static string decode (string s); static string decode (string s, String enc); // ENC encoding recommended use UTF-8
* The encoding and decoding methods in Java and the encodeURIComponent ()/decodeuricomponent () method in JS are common to the front and back, and there is no difference in the way in which the strings are processed;
URL special character encoding in JS and Java