HttpUtils (Java EE 5)

Java EE API


javax.servlet.http Class HttpUtils

java.lang.Object
  extended by javax.servlet.http.HttpUtils

Deprecated. As of Java(tm) Servlet API 2.3. These methods were only useful with the default encoding and have been moved to the request interfaces.


英文文档:

public class HttpUtils
extends Object


Constructor Summary
 
Method Summary
static StringBuffer
static Hashtable
static Hashtable
 
Methods inherited from class java.lang.Object
 

Constructor Detail

public HttpUtils()
构造一个空的 HttpUtils 对象。
英文文档:

HttpUtils

public HttpUtils()
Deprecated. 
Constructs an empty HttpUtils object.

Method Detail

public static java.util.Hashtable<K, V> parseQueryString(String s)
解析从客户端传递到服务器的查询字符串,并使用键-值对构建一个 HashTable 对象。查询字符串应该采用 GET 或 POST 方法打包的字符串形式,也就是说,应该是键=值 形式的键-值对,每个对与下一个对之间用 & 字符隔开。

在具有不同值的查询字符串中键可以出现多次。但是,在哈希表中键只能出现一次,其值是包含查询字符串发送的多个值的字符串数组。

哈希表中的键和值以其解码形式存储,因此任何 + 字符都将被转换为空格,以十六进制符号(如 %xx)形式发送的字符将被转换为 ASCII 字符。

s 包含要解析的查询的字符串
return 根据解析的键-值对构建的 HashTable 对象
ThrowsIllegalArgumentException: 如果查询字符串无效

英文文档:

parseQueryString

public static Hashtable parseQueryString(String s)
Deprecated. 
Parses a query string passed from the client to the server and builds a HashTable object with key-value pairs. The query string should be in the form of a string packaged by the GET or POST method, that is, it should have key-value pairs in the form key=value, with each pair separated from the next by a & character.

A key can appear more than once in the query string with different values. However, the key appears only once in the hashtable, with its value being an array of strings containing the multiple values sent by the query string.

The keys and values in the hashtable are stored in their decoded form, so any + characters are converted to spaces, and characters sent in hexadecimal notation (like %xx) are converted to ASCII characters.

Parameters:
s - a string containing the query to be parsed
Returns:
a HashTable object built from the parsed key-value pairs
Throws:
IllegalArgumentException - if the query string is invalid

public static java.util.Hashtable<K, V> parsePostData(int len, ServletInputStream in)
解析来自 HTML 表单的客户端使用 HTTP POST 方法和 application/x-www-form-urlencoded MIME 类型发送到服务器的数据。

通过 POST 方法发送的数据包含键-值对。在具有不同值的 POST 数据中键可以出现多次。但是,在哈希表中键只能出现一次,其值是包含 POST 方法发送的多个值的字符串数组。

哈希表中的键和值以其解码形式存储,因此任何 + 字符都将被转换为空格,以十六进制符号(如 %xx)形式发送的字符将被转换为 ASCII 字符。

len 指定也被传递给此方法的 ServletInputStream 对象的长度的整数,以字符为单位
in 包含从客户端发送的数据的 ServletInputStream 对象
return 根据解析的键-值对构建的 HashTable 对象
ThrowsIllegalArgumentException: 如果 POST 方法发送的数据无效

英文文档:

parsePostData

public static Hashtable parsePostData(int len,
                                      ServletInputStream in)
Deprecated. 
Parses data from an HTML form that the client sends to the server using the HTTP POST method and the application/x-www-form-urlencoded MIME type.

The data sent by the POST method contains key-value pairs. A key can appear more than once in the POST data with different values. However, the key appears only once in the hashtable, with its value being an array of strings containing the multiple values sent by the POST method.

The keys and values in the hashtable are stored in their decoded form, so any + characters are converted to spaces, and characters sent in hexadecimal notation (like %xx) are converted to ASCII characters.

Parameters:
len - an integer specifying the length, in characters, of the ServletInputStream object that is also passed to this method
in - the ServletInputStream object that contains the data sent from the client
Returns:
a HashTable object built from the parsed key-value pairs
Throws:
IllegalArgumentException - if the data sent by the POST method is invalid

public static StringBuffer getRequestURL(HttpServletRequest req)
使用 HttpServletRequest 对象中的信息重新构造客户端用于发出请求的 URL。返回的 URL 包含一个协议、服务器名称、端口号、服务器路径,但是不包含查询字符串参数。

因为此方法返回 StringBuffer 而不是字符串,所以可以轻松地修改 URL,例如,可以追加查询参数。

此方法对于创建重定向消息和报告错误很有用。

req 包含客户端请求的 HttpServletRequest 对象
return 包含重新构造的 URL 的 StringBuffer 对象

英文文档:

getRequestURL

public static StringBuffer getRequestURL(HttpServletRequest req)
Deprecated. 
Reconstructs the URL the client used to make the request, using information in the HttpServletRequest object. The returned URL contains a protocol, server name, port number, and server path, but it does not include query string parameters.

Because this method returns a StringBuffer, not a string, you can modify the URL easily, for example, to append query parameters.

This method is useful for creating redirect messages and for reporting errors.

Parameters:
req - a HttpServletRequest object containing the client's request
Returns:
a StringBuffer object containing the reconstructed URL


Submit a bug or feature

Copyright 2007 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.

一看就知道只有菜鸟才干这么无知的事啦。

PS : 未经我党受权你也可自由散发此文档。 如有任何错误请自行修正;若因此而造成任何损失请直接找人民主席,请勿与本人联系。谢谢!