Jsp HttpServletRequest usage

Source: Internet
Author: User
Tags port number

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 ());
  
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.