1. Coding Rulesjava.netClass Urlencoder
Urlencoderextends Object
Utility class for HTML form encoding. This class contains static methods for converting a String to the application/x-www-form-urlencoded
MIME format. For more information about HTML form encoding, consult the htmlspecification. When encoding a String, the following rules apply:
- The alphanumeric characters "
a
through" z
"," " A
through" Z
"and" 0
"through" "remain the same 9
.
- The special characters "", "" "," "
.
-
*
, and" _
"remain the same.
- The space character "is
converted to a plus sign" +
.
- All other characters is unsafe and is first converted to one or more bytes using some encoding scheme. Then each byte was represented by the 3-character string "
%xy
", wherexy is the two-digit hexadecimal representat Ion of the byte. The recommended encoding scheme to be UTF-8. However, for compatibility reasons, if a encoding is not specified and then the default encoding of the platform is used.
For example using UTF-8 as the encoding scheme the string "The Stringü@foo-bar" would get converted to "THE+STRING+%C3%BC %40foo-bar "because in UTF-8 the Characterüis encoded as both bytes C3 (hex) and BC (hex), and the character @ is encoded As one byte (hex).
- Since:
- JDK1.0
2. Encoding method
There are two methods: Encode (string s) and encode (string s,string encode)
Encode (String s) is encoded using the default encoding of the platform and is used with caution!
Encode (String s,string ENC) is encoded with the specified encoding, preferably in this way, to specify the encoding format, in order to avoid the changes in the environment to produce Chinese garbled
Java.net.URLEncoder resolve URL Chinese parameter garbled problem "2014-11-17"