java.net

Class URLEncoder

public class URLEncoder extends 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

Method Summary
static Stringencode(String s)
This method translates the passed in string into x-www-form-urlencoded format using the default encoding.
static Stringencode(String s, 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.

Method Detail

encode

public static String encode(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.

Parameters: s The String to convert

Returns: The converted String

encode

public static String encode(String s, 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.

Parameters: s The String to convert encoding The encoding to use for unsafe characters

Returns: The converted String

Throws: UnsupportedEncodingException If the named encoding is not supported

Since: 1.4