java.net
Class URLDecoder

java.lang.Object
  extended by java.net.URLDecoder

public class URLDecoder
extends Object

This utility class contains static methods that converts a string encoded in the x-www-form-urlencoded format to the original text. The x-www-form-urlencoded 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 given character encoding (default is "UTF-8").

This method is very useful for decoding strings sent to CGI scripts Written using on-line Java Platform 1.2/1.4 API Specification. Status: Believed complete and correct.

Since:
1.2

Constructor Summary
URLDecoder()
          Public contructor.
 
Method Summary
static String decode(String s)
          Deprecated.  
static String decode(String s, String encoding)
          This method translates the passed in string from x-www-form-urlencoded format using the given character encoding to decode the hex encoded unsafe characters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

URLDecoder

public URLDecoder()
Public contructor. Note that this class has only static methods.

Method Detail

decode

public static String decode(String s)
Deprecated. 

This method translates the passed in string from x-www-form-urlencoded format using the default encoding "UTF-8" to decode the hex encoded unsafe characters.

Parameters:
s - the String to convert
Returns:
the converted String

decode

public static String decode(String s,
                            String encoding)
                     throws UnsupportedEncodingException
This method translates the passed in string from x-www-form-urlencoded format using the given character encoding to decode the hex encoded unsafe characters. This implementation will decode the string even if it contains unsafe characters (characters that should have been encoded) or if the two characters following a % do not represent a hex encoded byte. In those cases the unsafe character or the % character will be added verbatim to the decoded result.

Parameters:
s - the String to convert
encoding - the character encoding to use the decode the hex encoded unsafe characters
Returns:
the converted String
Throws:
UnsupportedEncodingException - If the named encoding is not supported
Since:
1.4