- java.lang.Object
 -  
      
- java.net.URLDecoder
 
 
-  
       
public class URLDecoder extends Object
用于HTML表单解码的实用程序类。 此类包含用于解码application/x-www-form-urlencodedMIME格式的String的静态方法。转换过程与URLEncoder类使用的过程相反。 假设编码字符串中的所有字符是以下之一:“
a”到“z”,“A”到“Z”,“0”到“9”,以及“-”,“_”,“.“和”*“。 允许使用字符“%”,但它被解释为特殊转义序列的开头。转换中应用以下规则:
-  字母数字字符“ 
a”到“z”,“A”到“Z”和“0”到“9”保持不变。 -  特殊字符“ 
.”,“-”,“*”和“_”保持不变。 -  加号“ 
+”被转换为空格字符“”。 -  形式为“ 
%xy”的序列将被视为表示字节,其中xy是8位的两位十六进制表示。 然后,连续包含这些字节序列中的一个或多个的所有子串将被其编码将导致那些连续字节的字符替换。 可以指定用于解码这些字符的编码方案,或者如果未指定,则将使用平台的默认编码。 
这种解码器有两种可能的方式来处理非法字符串。 它可以单独留下非法字符,也可以抛出
IllegalArgumentException。 解码器采用哪种方法留给实现。- 从以下版本开始:
 - 1.2
 
 -  字母数字字符“ 
 
-  
        
       
-  
             
构造方法摘要
构造方法 构造器 描述 URLDecoder() 
 -  
             
 
-  
        
       
-  
             
方法详细信息
-  
decode
@Deprecated public static String decode(String s)
Deprecated.The resulting string may vary depending on the platform's default encoding. Instead, use the decode(String,String) method to specify the encoding.解码x-www-form-urlencoded字符串。 平台的默认编码用于确定哪些字符由“%xy”形式的任何连续序列表示。- 参数
 -  
              
s- 要解码的String - 结果
 - 
               新解码的 
              
String 
 
-  
decode
public static String decode(String s, String enc) throws UnsupportedEncodingException
使用特定编码方案解码application/x-www-form-urlencoded字符串。此方法与decode(java.lang.String,java.nio.charset.Charset)的行为相同,只是它使用给定的编码名称将为look up the charset 。
- Implementation Note:
 -  
              遇到非法字符串时,此实现将抛出
IllegalArgumentException。 - 参数
 -  
              
s- 要解码的String -  
              
enc- 支持的 character encoding的名称。 - 结果
 - 
               新解码的 
              
String - 异常
 -  
              
UnsupportedEncodingException- 如果需要查阅字符编码,但不支持命名字符编码 - 从以下版本开始:
 - 1.4
 - 另请参见:
 -  
              
URLEncoder.encode(java.lang.String, java.lang.String) 
 
-  
decode
public static String decode(String s, Charset charset)
使用特定的Charset解码application/x-www-form-urlencoded字符串。 提供的字符集用于确定形式为“%xy”的任何连续序列表示哪些字符。注意: World Wide Web Consortium Recommendation声明应该使用UTF-8。 不这样做可能会引入不兼容性。
- Implementation Note:
 -  
              遇到非法字符串时,此实现将抛出
IllegalArgumentException。 - 参数
 -  
              
s- 要解码的String -  
              
charset- 给定的字符集 - 结果
 - 
               新解码的 
              
String - 异常
 -  
              
NullPointerException- 如果s或charset是null -  
              
IllegalArgumentException- 如果实现遇到非法字符 - 从以下版本开始:
 - 10
 - 另请参见:
 -  
              
URLEncoder.encode(java.lang.String, java.nio.charset.Charset) 
 
 -  
 
 -