Request header related common information and usage

1. Common content of the Request header:

1、Accept

Specifies the MIME types that browsers or other clients can handle. Such as image/png and image/jpeg.

2、Accept-Encoding

Specifies the type of encoding that the browser knows how to handle. Such as gzip and compress.

3、Accept-Charset

Specifies the character set that the browser can use to display information. Such as ISO-8859-1.

4、Accept-Language

The specified header specifies the preferred language of the client, in which case the servlet produces results in multiple languages, such as en, en-us, ru, etc.

5、Authorization

Used by clients to identify themselves when visiting password-protected web pages.

6、Connection

Indicates whether the client can handle persistent HTTP connections. If it is Keep-Alive, it means that a persistent connection is used.

7、Content-Length

Applicable to POST requests, giving the size of the POST data in bytes.

8、Cookie

Request will bring local cookies to the server.

9、Host

Specifies the host and port of the original URL.

10、Refer

Indicates the URL of the Web page to point to. For example, if you click on a link to webpage 2 on webpage 1, when the browser requests webpage 2, the URL of webpage 1 will be included in the Referer (which can be visualized as someone's recommendation).

11. User-Agent (agent)

Identify the requesting browser or other client, and return different content to different types of browsers.

2. Related methods of the HttpServletRequest object (request header):

1. Get all Cookie objects:

Cookie[] getCookies()

2. Get all attribute names (return enumeration type):

Enumeration getAttributeNames()

3. Get all header names in the request (return enumeration type):

Enumeration getHeaderNames()

4. Get the names of all the parameters in the request (return an enumeration of String objects):

Enumeration getParameterNames()

5. Get the session associated with the current request (if not, one will be created):

HttpSession getSession()

6. Get the session associated with the current request (if there is no session and the following Boolean parameter is true, a new session will be returned):

HttpSession getSession(boolean create)

7. Obtain according to the attribute name

Object getAttribute(String name)

8. Obtain the authentication method of the Servlet:

String getAuthType() //如"BASIC"或"SSL",如果JSP没有收到保护则返回null

9. Get the name of the character encoding used by the principal:

String getCharacterEncoding()

10. Get the context type of the request:

String getContentType()

11. Get the context path (URL) of the request:

String getContextPath()

12. Obtain additional path information related to the URL sent by the request:

String getPathInfo()

13. Get the name and version of the protocol:

String getProtocol()

14. Obtain the IP of the client sending the request:

String getRemoteHost()

15. Obtain the request session ID:

String getRequestedSessionId()

16. Determine whether to use a secure channel (such as SSL-based HTTPS):

boolean isSecure()

17. Return the port number that received this request:

int getServerPort()

18. Encapsulate the parameters into a Map type:

int getParameterMap()

Guess you like

Origin blog.csdn.net/zhan_qian/article/details/127824701