Request object of the servlet

Source: Internet
Author: User

The following methods can be used to read HTTP headers in a Servlet program. These methods are available through the HttpServletRequest object.

1 cookie[] getcookies()

Returns an array that contains all the cookie objects that the client sends the request.

2 enumeration Getattributenames()

Returns an enumeration that contains the name of the property that is available for the request.

3 enumeration Getheadernames()

Returns an enumeration that contains all the header names that are contained in the request.

4 enumeration Getparameternames()

Returns an enumeration of a String object that contains the names of the parameters contained in the request.

5 HttpSession getsession()

Returns the current session that is associated with the request, or creates one if the request has no session sessions.

6 HttpSession getsession(Boolean Create)

Returns the current httpsession associated with the request, or returns a new session session if the current session is not present and the creation is true.

7 Locale GetLocale()

Based on the Accept-language header, returns the preferred locale for the client to accept the content.

8 Object getattribute(Stringname)

Returns the value of the named property as an object, or null if no attribute with the given name exists.

9 ServletInputStream getInputStream()

Use ServletInputStream to retrieve the principal of the request in binary data form.

Ten String getauthtype()

Returns the name of the authentication scheme used to protect the Servlet, for example, "BASIC" or "SSL", or null if the JSP is not protected.

String getcharacterencoding()

Returns the name of the character encoding used in the request body.

String getcontenttype()

Returns the MIME type of the request principal and returns NULL if the type is not known.

String Getcontextpath()

Returns the part of the request URI that indicates the request context.

String getheader(Stringname)

Returns the value of the specified request header as a string.

String GetMethod()

Returns the name of the requested HTTP method, for example, GET, POST, or PUT.

String getparameter(Stringname)

Returns the value of the request parameter as a string, or null if the argument does not exist.

-String getpathinfo()

When the request is issued, returns any additional path information related to the URL sent by the client.

String getprotocol()

Returns the name and version of the request agreement.

String getquerystring()

Returns the query string contained in the request URL after the path.

String getremoteaddr()

Returns the Internet Protocol (IP) address of the client sending the request.

String getremotehost()

Returns the fully qualified name of the client that sent the request.

String getremoteuser()

If the user is authenticated, returns the logged on user who made the request, or null if the user is not authenticated.

GetrequesturiString ()

Returns part of the URL of the request from the protocol name until the first line of the HTTP request is returned in the query string.

String Getrequestedsessionid()

Returns the session ID specified by the client.

String Getservletpath()

Returns part of the URL of the request that called the JSP.

String[] getparametervalues(Stringname)

Returns an array of String objects containing the values of all given request parameters and returns null if the argument does not exist.

Boolean issecure()

Returns a Boolean value that indicates whether the request uses a secure channel, such as HTTPS.

getcontentlengthInt ()

Returns the length of the request body in bytes, providing an input stream, or 1 if the length is unknown.

int getintheader(Stringname)

Returns the value of the specified request header to an int value.

int Getserverport()

Returns the port number to which this request was received.

The following are important header information from the browser side, which can be used frequently in web programming:

You can use Request.getheader (attributename) to get properties such as Request.getheader ("accept") to get the supported format of the browser

Accept This header information to specify the MIME types that the browser or other client can handle. A value of Image/png or Image/jpeg is the two most common possible values.

Accept-charset This header information specifies the character set that the browser can use to display information. such as Iso-8859-1.

accept-encoding This header information specifies the type of encoding that the browser knows how to handle. The value of gzip or compress is the two most common possible values.

Accept-language This header specifies the preferred language for the client, in which case the Servlet produces results in multiple languages. For example, en, en-us, RU, etc.

Authorization This header information is used by clients to identify themselves when accessing password-protected Web pages.

Connection This header information indicates whether the client can handle persistent HTTP connections. Persistent connections allow clients or other browsers to retrieve multiple files through a single request. A value of keep-alive means that a persistent connection is used.

Content-length This header information applies only to post requests and gives the size of the post data in bytes.

Cookie This header message returns the cookies that were previously sent to the browser to the server.

Host This header information specifies the hosts and ports in the original URL.

if-modified-since This header information indicates the page that the client wants only if the page has changed since the specified date. If no new results are available, the server sends a 304 code that represents the not Modified header information.

if-unmodified-since This header message is the antithesis of if-modified-since, which specifies that the operation will succeed only if the document is older than the specified date.

Referer This header indicates the URL of the Web page to which the message is pointing. For example, if you click a link to page 2 on page 1, when the browser requests page 2 o'clock, the URL of page 1 is included in the Referer header message.

user-agent This header information identifies the browser or other client that made the request and can return different content to different types of browsers.

Request object of the servlet

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.