📄 request.java
字号:
package mypkg.jspsmart.upload;
import java.util.Enumeration;
import java.util.Hashtable;
/**
* The equivalent of ServletRequest Class. This is a dependant object wich can't
* be directly instantiate.
*
* @author jimshen
*
*/
public class Request {
private Hashtable parameters;
private int counter;
Request() {
parameters = new Hashtable();
counter = 0;
}
protected void putParameter(String name, String value) {
if (name == null) {
throw new IllegalArgumentException(
"The name of an element cannot be null.");
}
if (parameters.containsKey(name)) {
Hashtable hashtable = (Hashtable) parameters.get(name);
hashtable.put(new Integer(hashtable.size()), value);
} else {
Hashtable hashtable1 = new Hashtable();
hashtable1.put(new Integer(0), value);
parameters.put(name, hashtable1);
counter++;
}
}
/**
* Returns the value of a request parameter as a String, or null if the
* parameter does not exist. Request parameters are extra information sent
* with the request. You should only use this method when you are sure the
* parameter has only one value. If the parameter might have more than one
* value, use getParameterValues(java.lang.String).
*
* If you use this method with a multivalued parameter, the value returned
* is equal to the first value in the array returned by getParameterValues.
*
* If the parameter data was sent in the request body, such as occurs with
* an HTTP POST request, then reading the body directly via #getInputStream
* or #getReader can interfere with the execution of this method.
*
* @param name
* a String specifying the name of the parameter
* @return a String representing the single value of the parameter
* @see getParameterValues(java.lang.String)
*/
public String getParameter(String name) {
if (name == null) {
throw new IllegalArgumentException(
"Form's name is invalid or does not exist (1305).");
}
Hashtable hashtable = (Hashtable) parameters.get(name);
if (hashtable == null) {
return null;
} else {
return (String) hashtable.get(new Integer(0));
}
}
/**
* Returns an Enumeration of String objects containing the names of the
* parameters contained in this request. If the request has no parameters,
* the method returns an empty Enumeration.
*
* @return an Enumeration of String objects, each String containing the name
* of a request parameter; or an empty Enumeration if the request
* has no parameters
*
*/
public Enumeration getParameterNames() {
return parameters.keys();
}
/**
* Returns an array of String objects containing all of the values the given
* request parameter has, or null if the parameter does not exist. If the
* parameter has a single value, the array has a length of 1.
*
*
* @param name
* a String containing the name of the parameter whose value is
* requested
* @return an array of String objects containing the parameter's values
* @see getParameter(java.lang.String)
*/
public String[] getParameterValues(String name) {
if (name == null) {
throw new IllegalArgumentException(
"Form's name is invalid or does not exist (1305).");
}
Hashtable hashtable = (Hashtable) parameters.get(name);
if (hashtable == null) {
return null;
}
String as[] = new String[hashtable.size()];
for (int i = 0; i < hashtable.size(); i++) {
as[i] = (String) hashtable.get(new Integer(i));
}
return as;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -