Tag Archives: JavaWeb——HttpServletRequest

JavaWeb HttpServletRequest (How to Get Line, Header and Body)

introduce

HttpServletRequest defines a series of methods to obtain the request line, request header and request body, and can store information as a domain

common method

Request line

String getRemoteAddr()

Parameter: None

Return value: String

Meaning of return value: obtain the client IP address

Function: obtain the client IP address

Request header

String getHead(String name)

Parameters:

String Name: the name of the request header

Return value: String

Meaning of return value: get the value corresponding to the request header

Function: get the value corresponding to the request body

Enumeration getHeaderNames()

Parameter: None

Return value: enumeration < String>

Return value meaning: get the enumeration of all request header names

Function: get the enumeration of all request header names

Request body

String getParameter(String name)

Parameters:

String Name: the name of the request body parameter

Return value: String

Meaning of return value: get the value corresponding to the request body parameter name

Function: get the value corresponding to the request body parameter name

Enumeration< String> getParameterNames()

Parameter: None

Return value: enumeration & lt; String>

Meaning of return value: get the enumeration of all request headers

Function: get the enumeration of all request headers

Request field

void setAttribute(String name ,Object obj)

Parameters:

String Name: the name of the information in the field

Object obj: field value

Return value: None

Return value meaning: None

Scope: store information in the request domain for forwarding

Object geAttribute(String name)

Parameters:

String Name: the name of the information in the field

Return value: object

Meaning of return value: get the object corresponding to the information name in the field

Scope: get the object corresponding to the information name in the domain

Other

void setCharacterEncoding(String name)

Parameters:

String Name: character set

Return value: None

Return value meaning: None

Function: set the character set in the request body