1. Related interfaces
HttpServletRequest
The most commonly used method of the HttpServletRequest interface is to obtain the parameters in the request, which are generally the data in the client form. At the same time, the HttpServletRequest interface can obtain the name transmitted by the client, the host name and IP address of the server that generates the request and receives the request, and also obtains information such as the communication protocol being used by the client. The following table shows the common methods of the interface HttpServletRequest.
Description: The HttpServletRequest interface provides many methods.
Common methods of interface HttpServletRequest
method |
illustrate |
getAttributeNames() |
Returns the set of names of all attributes of the current request |
getAttribute(String name) |
Returns the property value specified by name |
getCookies() |
Returns the cookie sent by the client |
getsession() |
Returns the session associated with the client, or null if no session is assigned to the client |
getsession(boolean create) |
Returns the session related to the client. If no session is assigned to the client, create a session and return |
getParameter(String name) |
Get the parameters in the request, which are specified by name |
getParameterValues(String name) |
Returns the parameter value in the request, the parameter value is specified by name |
getCharacterEncoding() |
Returns the requested character encoding |
getContentLength() |
Returns the effective length of the request body |
getInputStream() |
Get data from the requested input stream |
getMethod() |
Get the method of sending the request, such as get, post |
getParameterNames() |
Get the names of all parameters in the request |
getProtocol() |
Get the protocol name used by the request |
getReader() |
Get the data stream of the request body |
getRemoteAddr() |
Get the IP address of the client |
getRemoteHost() |
Get the client's name |
getServerName() |
Returns the name of the server accepting the request |
getServerPath() |
Get the path of the requested file |
HttpServletResponse
In servlets, the HttpServletResponse interface is used when the server responds to a request from the client. To set the type of the response, use the setContentType() method. To send character data, you can use getWriter() to return an object. The following table shows the common methods of the interface HttpServletResponse.
Common methods of interface HttpServletResponse
method |
illustrate |
addCookie(Cookie cookie) |
Add the specified cookie to the current response |
addHeader(String name,String value) |
Add the specified name and value to the response headers |
containsHeader(String name) |
Returns a boolean value that determines whether the response header is set |
encodeURL(String url) |
Encode the specified URL |
sendError(int sc) |
Send an error to the client with the specified status code |
sendRedirect(String location) |
send a provisional response to the client |
setDateHeader(String name,long date) |
Set the given name and date to the header of the response |
setHeader(String name,String value) |
Set the given name and value to the header of the response |
setStatus(int sc) |
Set the status code for the current response |
setContentType(String ContentType) |
Set the MIME type of the response |
2. Some differences
javax.servlet.http.HttpServletRequest