HttpServletRequest method summary and requst common methods

The HttpServletRequest object represents the client's request. When the client accesses the server through the HTTP protocol, all the information in the HTTP request header is encapsulated in this object. The developer can obtain the client's information through the method of this object.
 
Common methods of request
Get client information
The getRequestURL method returns the full URL at the time the client made the request.
The getRequestURI method returns the resource name portion of the request line.
The getQueryString method returns the parameter part of the request line.
The getRemoteAddr method returns the IP address of the requesting client
The getRemoteHost method returns the full hostname of the requesting client
The getRemotePort method returns the network port number used by the client
The getLocalAddr method returns the IP address of the WEB server.
The getLocalName method returns the host name of the WEB server
getMethod gets the client request method
 
get client request header
getHead(name) method
getHeaders(String name) method
getHeaderNames method
 
Obtain client request parameters (data submitted by the client)
getParameter(name): Get the parameter value of the specified name. This is one of the most commonly used methods.
getParameterValues(String name): Gets an array of all values ​​for the specified name parameter. It is suitable for cases where one parameter name corresponds to multiple values. Such as the check box in the page form, the value submitted by the multi-select list.
getParameterNames(): Returns an Enumeration object containing all parameter names in the request message. By traversing the Enumeration object, you can get all the parameter names in the request message.
getParameterMap(): Returns a Map object that saves all parameter names and values ​​in the request message. The key of the Map object is the parameter name of the string type, and the value is the value array of the Object type corresponding to this parameter
 
After the request forwarding process of calling the RequestDispatcher.forward method ends,
The browser address bar keeps the original URL address unchanged.
The HttpServletResponse.sendRedirect method responds directly to the browser's request, and the result of the response is to tell the browser to re-issue an access request to another URL;
The RequestDispatcher.forward method forwards the request to another resource inside the server. The browser only knows that the request has been sent and the response has been received, but it does not know that the forwarding behavior has occurred inside the server program.
The caller and callee of the RequestDispatcher.forward method share the same request object and response object, and they belong to the same access request and response process;
The HttpServletResponse.sendRedirect method caller and callee use their own request object and response object, which belong to two independent access request and response processes.

Guess you like

Origin blog.csdn.net/fuxingsheng1/article/details/80936378