Request object
It is mainly used to receive the request information sent from the client. The client's request information is encapsulated in the request object, which can be used to understand the customer's requirements and then respond. It is an instance of the httpservletrequest class.
Serial number method description
1 object getattribute (string name) returns the attribute value of the specified attribute
2 enumeration getattributenames () returns the enumeration of all available attribute names
3 string getcharacterencoding () returns the character encoding method
4 int getcontentlength () returns the length of the Request body (in bytes)
5 string getcontenttype () Get the MIME type of the Request body
6. servletinputstream getinputstream () obtains the binary stream of a row in the Request body.
7 string getparameter (string name) returns the parameter value of the specified name parameter.
8 enumeration getparameternames () returns the enumeration of available parameter names
9 string [] getparametervalues (string name) returns an array containing all values of the parameter name, such as the checkbox option. This method is available.
10 string getprotocol () returns the protocol type and version number of the request.
11 string getscheme () returns the scheduler name used for the request, such as HTTP. HTTPS and FTP.
12 string getservername () returns the server host name that receives the request
13 int getserverport () returns the port number used by the server to accept the request.
14 bufferedreader getreader () returns the decoded Request body
15 string getremoteaddr () returns the IP address of the client sending the request.
16 string getremotehost () returns the client host name that sent this request
17 void setattribute (string key, object OBJ) set the attribute Attribute Value
18 string getrealpath (string path) returns the actual path of a virtual path.
19 void setcharacterencoding (string Code) is used to set the passed character encoding and can be used to solve the garbled problem.
20
<% @ Page contenttype = "text/html; charset = gb2312" %>
<% Request. setcharacterencoding ("gb2312"); %>
<HTML>
<Head>
<Title> request object_example 1 </title>
</Head>
<Body bgcolor = "# fffff0">
<Form action = "" method = "Post">
<Input type = "text" name = "qwe">
<Input type = "Submit" value = "Submit">
</Form>
Request Method: <% = request. getmethod () %> <br>
Requested Resource: <% = request. getrequesturi () %> <br>
Request Protocol: <% = request. getprotocol () %> <br>
Request file name: <% = request. getservletpath () %> <br>
IP address of the requested server: <% = request. getservername () %> <br>
Request server port: <% = request. getserverport () %> <br>
Client IP address: <% = request. getremoteaddr () %> <br>
Client Host Name: <% = request. getremotehost () %> <br>
Value for form submission: <% = request. getparameter ("qwe") %> <br>
</Body>
</Html>
<% @ Page contenttype = "text/html; charset = gb2312" %>
<% Request. setcharacterencoding ("gb2312"); %>
<% @ Page import = "Java. util. enumeration" %>
<HTML>
<Head>
<Title> request object_example 2 </title>
</Head>
<Body bgcolor = "# fffff0">
<Form action = "" method = "Post">
Username: <input type = "text" name = "username"> & nbsp;
Password: <input type = "text" name = "userpass"> & nbsp;
<Input type = "Submit" value = "enter">
</Form>
<%
String STR = "";
If (request. getparameter ("username ")! = NULL & request. getparameter ("userpass ")! = NULL ){
Enumeration enumt = request. getparameternames ();
While (enumt. hasmoreelements ()){
STR = enumt. nextelement (). tostring ();
Out. println (STR + ":" + request. getparameter (STR) + "<br> ");
}
}
%>
</Body>
</Html>
<% @ Page contenttype = "text/html; charset = gb2312" %>
<% Request. setcharacterencoding ("gb2312"); %>
<HTML>
<Head>
<Title> request object_example 3 </title>
</Head>
<Body bgcolor = "# fffff0">
<Form action = "" method = "Post">
Good at: <input type = "checkbox" name = "CB" value = "on1"> VC ++ & nbsp;
<Input type = "checkbox" name = "CB" value = "on2"> JAVA & nbsp;
<Input type = "checkbox" name = "CB" value = "on3"> Delphi & nbsp;
<Input type = "checkbox" name = "CB" value = "on4"> VB & nbsp;
<Br>
<Input type = "Submit" value = "enter" name = "qwe">
</Form>
<%
If (request. getparameter ("qwe ")! = NULL ){
For (INT I = 0; I <request. getparametervalues ("CB"). length; I ++ ){
Out. println ("CB" + I + ":" + request. getparametervalues ("CB") [I] + "<br> ");
}
Out. println (request. getparameter ("qwe "));
}
%>
</Body>
</Html>