Servlet Request object, servletrequest

Source: Internet
Author: User

Servlet Request object, servletrequest

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

 

1 Cookie []GetCookies()

Returns an array containing all Cookie objects sent by the client.

2 EnumerationGetAttributeNames()

Returns an enumeration that contains the attribute names available for the request.

3 EnumerationGetHeaderNames()

Returns an enumeration of all headers contained in the request.

4 EnumerationGetParameterNames()

Returns the enumeration of a String object, including the name of the parameter contained in the request.

5 HttpSessionGetSession()

Returns the current session associated with the request, or creates a session if the request does not have a session.

6 HttpSessionGetSession(Boolean create)

Returns the current HttpSession associated with the request, or if there is no current session and the creation is true, a new session is returned.

7 LocaleGetLocale()

Based on the Accept-Language header, return the preferred region settings for the client to Accept content.

8 ObjectGetAttribute(Stringname)

Returns the value of a named property in the form of an object. If no property with a given name exists, null is returned.

9 ServletInputStreamGetInputStream()

Use ServletInputStream to retrieve the Request body in the form of binary data.

10 StringGetAuthType()

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

11 StringGetCharacterEncoding()

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

12 StringGetContentType()

The MIME type of the Request body. If the type is unknown, null is returned.

13 StringGetContextPath()

Returns the request URI that indicates the request context.

14 StringGetHeader(Stringname)

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

15 StringGetMethod()

The name of the HTTP Method returned, for example, GET, POST, or PUT.

16 StringGetParameter(Stringname)

Return the value of the Request Parameter in string form, or return null if the parameter does not exist.

17 StringGetPathInfo()

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

18 StringGetProtocol()

Returns the name and version of the request protocol.

19 StringGetQueryString()

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

20 StringGetRemoteAddr()

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

21 StringGetRemoteHost()

Returns the fully qualified name of the client sending the request.

22 StringGetRemoteUser()

If the user has passed the authentication, return the login user sending the request, or if the user has not passed the authentication, return null.

23 StringGetRequestURI()

Return part of the request URL from the protocol name to the query string in the first line of the HTTP request.

24 StringGetRequestedSessionId()

Returns the session ID specified by the client.

25 StringGetServletPath()

Return part of the URL of the request that calls JSP.

26 String []GetParameterValues(Stringname)

Returns an array of string objects, containing the values of all given request parameters. If the parameter does not exist, null is returned.

27 booleanIsSecure()

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

28 intGetContentLength()

The length of the Request body is returned in bytes, and the input stream is provided, or-1 is returned if the length is unknown.

29 intGetIntHeader(Stringname)

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

30 intGetServerPort()

Returns the port number of the request.

 

The following are important information from the browser.Header information, Which can be frequently used in Web programming:

You can use request. getHeader (attributeName) to obtain the attributes. For example, request. getHeader ("accept") can obtain the supported formats of the browser.

AcceptThis header specifies the MIME type that the browser or other clients can process. The value image/png or image/jpeg is the most common two possible values.

Accept-CharsetThis header specifies the character set that the browser can use to display information. For example, ISO-8859-1.

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

Accept-LanguageThis header specifies the preferred language of the client. In this case, the Servlet will produce results in multiple languages. For example, en, en-us, and ru.

AuthorizationThis header identifies a client when accessing a password-protected webpage.

ConnectionThis header indicates whether the client can process persistent HTTP connections. Persistent connections allow the client or other browsers to retrieve multiple files using a single request. The value Keep-Alive indicates that a persistent connection is used.

Content-LengthThis header information only applies to POST requests and returns the size (in bytes) of POST data ).

CookieThis header information returns the cookies sent to the browser to the server.

HostThis header specifies the host and port in the original URL.

If-Modified-SinceThis header indicates the page that the client wants only when the page has been changed after the specified date. If no new results are available, the server sends a 304 code, indicating the Not Modified header information.

If-Unmodified-SinceThis header is the opposite of If-Modified-Since. It specifies that the operation will succeed only when the document is earlier than the specified date.

RefererThis header indicates the URL of the Web page to which it is directed. For example, if you click a link to page 2 on page 1, when the browser requests page 2, the URL of page 1 will be included in the Referer header information.

User-AgentThis header identifies the requested browser or other clients and can return different content to different types of browsers.

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.