URL Origin:
In general, URLs can use only English letters, Arabic numerals, and certain punctuation marks, and cannot use other text or symbols. For example, the world has the English alphabet url "http://www.abc.com", but there is no Greek alphabet url "http://www.aβγ.com" (read as alpha-beta-gamma. com). This is because the network standard RFC 1738 makes the hard rules:
"... Only alphanumerics [0-9a-za-z], the special characters "$-_.+!*" (), "[not including the quotes-ed], and reserved charact ERs used for their reserved purposes could be used unencoded within a URL. "
"Only letters and numbers [0-9a-za-z], some special symbols" $-_.+!* "()," [not including double quotes], and some reserved words can be used without encoding directly for the URL. " ”
This means that if there is a Chinese character in the URL, it must be encoded and used. However, the trouble is that RFC 1738 does not prescribe specific coding methods, but instead gives the application (browser) its own decision. This causes "URL coding" to become a confusing area.
Let's see how confusing "url coding" is. I'll analyze four different situations in turn, in each case, the URL encoding method of the browser is not the same. After explaining their differences, I'll say how to use JavaScript to find a unified coding method.
The specific code is as follows:(remember, be sure to note the coding)
PackageCom.util;Importjava.io.UnsupportedEncodingException;/*** URL transcoding, decoding * *@authorLifq * @date 2015-3-17 pm 04:09:35*/ Public classUrlutil {Private Final StaticString ENCODE = "GBK"; /*** URL Decoding * *@returnString *@authorLifq * @date 2015-3-17 pm 04:09:51*/ Public Staticstring geturldecoderstring (String str) {string result= ""; if(NULL==str) { return""; } Try{result=Java.net.URLDecoder.decode (str, ENCODE); } Catch(unsupportedencodingexception e) {e.printstacktrace (); } returnresult; } /*** URL transcoding * *@returnString *@authorLifq * @date 2015-3-17 pm 04:10:28*/ Public Staticstring geturlencoderstring (String str) {string result= ""; if(NULL==str) { return""; } Try{result=Java.net.URLEncoder.encode (str, encode); } Catch(unsupportedencodingexception e) {e.printstacktrace (); } returnresult; } /** * * @returnvoid *@authorLifq * @date 2015-3-17 pm 04:09:16*/ Public Static voidMain (string[] args) {String str= "Test 1"; SYSTEM.OUT.PRINTLN (geturlencoderstring (str)); SYSTEM.OUT.PRINTLN (geturldecoderstring (str)); }}
Java implements URL transcoding, decoding