Saturday, 23 April 2016

What are main methods of HttpServletResponse interface ?


Interface HttpServletResponse extends the ServletResponse interface to provide HTTP-specific functionality in sending a response.

For example, it has methods to access HTTP headers and cookies.
The servlet container creates an HttpServletResponse object and passes it as an argument to the servlet's service methods (doGet, doPost ...).

HttpServletResponse methods
void addCookie(Cookie cookie)
Adds the specified cookie to the response.

void addHeader(String name, String value)
Adds a response header with the given name and value.

void addDateHeader(String name, long date)
void addIntHeader(String name, int value)
Adds a response header with the given name and date-value / integer value.

void setDateHeader(String name, long date)
void setIntHeader(String name, int value)
Sets a response header with the given name and date-value / integer value.

void setHeader(String name, String value)
Sets a response header with the given name and value.

boolean containsHeader(String name)
Returns a boolean indicating whether the named response header has already been set.

void sendRedirect(String location)
Sends a temporary redirect response to the client using the specified redirect location URL.

String encodeRedirectURL(String url)
Encodes the specified URL for use in the sendRedirect method or, if encoding is not needed, returns the URL unchanged.

String encodeURL(String url)
Encodes the specified URL by including the session ID in it, or, if encoding is not needed, returns the URL unchanged.

void sendError(int sc)
Sends an error response to the client using the specified status code and clearing the buffer.

void sendError(int sc, String msg)
Sends an error response to the client using the specified status.

void setStatus(int code)
Sets the status code for this response.

void setContentType(String type)
String getContentType()
Sets the content type of the response being sent to the client, if the response has not been committed yet.

void setLocale(Locale loc)
Locale getLocale()
Sets the locale of the response, if the response has not been committed yet.

void setCharacterEncoding(String charset)
String getCharacterEncoding()
Sets the character encoding (MIME charset) of the response being sent to the client, for example, to UTF-8.

void flushBuffer()
Forces any content in the buffer to be written to the client.

boolean isCommitted()
Returns a boolean indicating if the response has been committed.

void reset()
Clears any data that exists in the buffer as well as the status code and headers.

void resetBuffer()
Clears the content of the underlying buffer in the response without clearing headers or status code.

void setBufferSize(int size)

Sets the preferred buffer size for the body of the response.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.