HttpServletResponse Class

HttpServletResponse class enables a servlet to formulate an HTTP response to a client. Several constants are defined. These correspond to the different status codes that can be assigned to an HTTP response.

MethodDescription
void addCookie(Cookie cookie)It adds the cookie to the HTTP response.
boolean containsHeader(String field)It returns true if the HTTP response header contains a field named field.
String encodeURL(String url)It determines if the session ID must be encoded in the URL identified as URL. If so, returns the modified version of the URL.
Otherwise, returns URL. All URLs generated by a servlet should be processed by this method.
String encodeRedirectURL(String url)It determines if the session ID must be encoded in the URL identified as URL. If so, returns the modified version of the URL.
Otherwise, returns URL. All URLs passed to sendRedirect( ) should be processed by this method.
void sendError(int c) throws IOExceptionIt sends the error code c to the client.
void sendError(int c, String s)
throws IOException
It sends the error code c and message s to the client.
void sendRedirect(String url)
throws IOException
It redirects the client to URL.
void setDateHeader(String field, long msec)It adds the field to the header with date value equal to msec (milliseconds since midnight, January 1, 1970, GMT).
void setHeader(String field, String value)It adds the field to the header with the value equal to value.
void setIntHeader(String field, int value)It adds the field to the header with the value equal to value.
void setStatus(int code)It sets the status code for this response to code.