The common interface https tutorial ervletrequest inherits from servletrequest. The requests sent by the client browser are encapsulated into an httpservletrequest object. All information includes the request address, request parameters, submitted data, ip address of the uploaded file client, and even the client operating system. Httpservletresponse inherits the servletresponse interface and provides methods related to the http protocol.
<% @ Page import = "java. util. *" %>
<%
String title = "httpservletrequest method values ";
Map entries = new treemap ();
Entries. put ("getcharacterencoding", request. getcharacterencoding ());
Entries. put ("getcontentlength", "" + request. getcontentlength ());
Entries. put ("getcontenttype", request. getcontenttype ());
Entries. put ("getlocale", request. getlocale ());
Entries. put ("getprotocol", request. getprotocol ());
Entries. put ("getremoteaddr", request. getremoteaddr ());
Entries. put ("getremotehost", request. getremotehost ());
Entries. put ("getscheme", request. getscheme ());
Entries. put ("getservername", request. getservername ());
Entries. put ("getserverport", "" + request. getserverport ());
Entries. put ("issecure", "" + request. issecure ());
Request. setattribute ("_ table_title", title );
Request. setattribute ("_ table_entries", entries );
Out. println (request. getcharacterencoding ());
%>
Httpservletrequest method summary
The getscheme () method returns the request plan, such as http, https, or ftp.
The getservername () method returns the host name of the server to which the request is sent.
The getserverport () method returns the port number of the sent request.
Getcontextpath () returns the root directory of the request address, which is switched to/, but not ended.
A commonly used connection string for obtaining the server address is:
String path = request. getcontextpath ();
String basepath = request. getscheme () + ": //" + request. getservername () + ":" + request. getserverport () + path + "/";
Getcookies ()
Getmethod () gets the request method, such as get, post, or put
Getrequesturl () get the request url (Uniform Resource Locator)
Getrequesturi () get the request uri (Uniform Resource Identifier)
Getsession () gets the corresponding session
Getheadernames () returns an enumeration (traversal) of all header names contained in the request)
The usage is as follows:
Enumeration en = request. getheadernames ();
While (en. hasmoreelements ()){
Out. print (en. nextelement ());
}