Request Object
The client's request information is encapsulated in the requests object to understand the customer's needs and respond. It is an instance of the HttpServletRequest class.
Ordinal method Description
1 Object getattribute (String name) returns the property value of the specified property
2 enumeration Getattributenames () returns an enumeration of all available property names
3 String getcharacterencoding () returns the character encoding method
4 int Getcontentlength () returns the length of the request body (in bytes)
5 String getContentType () Gets the MIME type of the request body
6 ServletInputStream getInputStream () gets the binary stream of a row in the request body
7 string GetParameter (string name) returns the parameter value of name specified parameter
8 enumeration Getparameternames () returns an enumeration of the available parameter names
9 string[] Getparametervalues (String name) returns an array of all values that contain the parameter name
Ten String Getprotocol () returns the protocol type and version number of the request
One String Getscheme () returns the plan name of the request, such as: Http.https and FTP, etc.
String getServerName () returns the host name of the server that accepts the request
int Getserverport () returns the port number used by the server to accept this request
BufferedReader Getreader () returns the decoded request body
String getremoteaddr () returns the IP address of the client that sent this request
String Getremotehost () returns the host name of the client that sent this request
$ void SetAttribute (String key,object obj) to set property values for a property
String Getrealpath (string path) returns the true path of a virtual path
19
20
<%@ page contenttype= "text/html;charset=gb2312"%>
<%request.setcharacterencoding ("gb2312");%>
<title>request a00-206 </title>
<body bgcolor= "#FFFFF0" >
<form action= "" method= "POST" >
<input type= "text" name= "Qwe" >
<input type= "Submit" value= "Submission" >
</form>
Request method: <%=request.getmethod ()%><br>
Requested resource: <%=request.getrequesturi ()%><br>
Requested protocol: <%=request.getprotocol ()%><br>
Requested file name: <%=request.getservletpath ()%><br>
Ip:<%=request.getservername ()%><br> of the requested server
Port of the requesting server: <%=request.getserverport ()%><br>
Client IP Address: <%=request.getremoteaddr ()%><br>
Client host Name: <%=request.getremotehost ()%><br>
Value submitted by Form: <%=request.getparameter ("Qwe")%><br>
</body>
<%@ page contenttype= "text/html;charset=gb2312"%>
<%request.setcharacterencoding ("gb2312");%>
<%@ page import= "Java.util.Enumeration"%>
<title>request 250-10 </title>
<body bgcolor= "#FFFFF0" >
<form action= "" method= "POST" >
User name: <input type= "text" name= "username" >
Password: <input type= "text" name= "Userpass" >
<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>
<%@ page contenttype= "text/html;charset=gb2312"%>
<%request.setcharacterencoding ("gb2312");%>
<title> e20-090 </title>
<body bgcolor= "#FFFFF0" >
<form action= "" method= "POST" >
Good: <input type= "checkbox" Name= "CB" value= "ON1" >VC++
<input type= "checkbox" Name= "CB" value= "ON2" >JAVA
<input type= "checkbox" Name= "CB" value= "ON3" >DELPHI
<input type= "checkbox" Name= "CB" value= "ON4" >VB
<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>
JSP detailed Request Object