java.net
Class URLEncoder

java.lang.Object
java.net.URLEncoder
- public class URLEncoder
- extends java.lang.Object
This utility class contains static methods that converts a
string into a fully encoded URL string in x-www-form-urlencoded
format. This format replaces certain disallowed characters with
encoded equivalents. All upper case and lower case letters in the
US alphabet remain as is, the space character (' ') is replaced with
'+' sign, and all other characters are converted to a "%XX" format
where XX is the hexadecimal representation of that character in a
certain encoding (by default, the platform encoding, though the
standard is "UTF-8").
This method is very useful for encoding strings to be sent to CGI scripts
|
Constructor Summary |
private |
URLEncoder()
Private constructor that does nothing. |
|
Method Summary |
static java.lang.String |
encode(java.lang.String s)
Deprecated. |
static java.lang.String |
encode(java.lang.String s,
java.lang.String encoding)
This method translates the passed in string into x-www-form-urlencoded
format using the character encoding to hex-encode the unsafe characters. |
private static boolean |
isSafe(char c)
Private static method that returns true if the given char is either
a uppercase or lowercase letter from 'a' till 'z', or a digit froim
'0' till '9', or one of the characters '-', '_', '.' or '*'. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
hex
private static final java.lang.String hex
- Used to convert to hex. We don't use Integer.toHexString, since
it converts to lower case (and the Sun docs pretty clearly
specify upper case here), and because it doesn't provide a
leading 0.
- See Also:
- Constant Field Values
URLEncoder
private URLEncoder()
- Private constructor that does nothing. Included to avoid a default
public constructor being created by the compiler.
encode
public static java.lang.String encode(java.lang.String s)
- Deprecated.
- This method translates the passed in string into x-www-form-urlencoded
format using the default encoding. The standard encoding is
"UTF-8", and the two-argument form of this method should be used
instead.
encode
public static java.lang.String encode(java.lang.String s,
java.lang.String encoding)
throws java.io.UnsupportedEncodingException
- This method translates the passed in string into x-www-form-urlencoded
format using the character encoding to hex-encode the unsafe characters.
- Since:
- 1.4
isSafe
private static boolean isSafe(char c)
- Private static method that returns true if the given char is either
a uppercase or lowercase letter from 'a' till 'z', or a digit froim
'0' till '9', or one of the characters '-', '_', '.' or '*'. Such
'safe' character don't have to be url encoded.