HttpServletResponse

HttpServletResponse interface belongs to javax.servlet package and extends ServletResponse interface. HttpServletResponse helps us to send data back to web browser. e.g. set cookies, session, data, etc.

In short, HttpServletRequest helps us to send data from web browser to servlet and HttpServletResponse sends data back from Servlet to web browser.

HttpServletResponse Methods

void addCookie(Cookie cookie) → This method helps us to add cookie in the response object.

void addDateHeader(String name, long date) → This method add header as a key as a String and value as a long in the response object.

void addHeader(String name, String value) → This method add header as a key value pair in the response object.

void addIntHeader(String name, int value) → This method add header as a key as a String and value as an int in the response object.

boolean containsHeader(String name) → This method will true if header with a specfic name is present in the response object.

void setDateHeader(String name, long date) → This method add header as a key as a String and value as date in the response object.

void sendError(int sccode) → This method set the error code in the response object and clears buffer.

void sendError(int code, String msg) → This method set the error code and message in the response object.

void setLocale(Locale loc) → This method set locale in the response object, if the response has not been committed yet.

void setStatus(int sc) → This method Set the status code in the reponse object.

void setContentType(String type) → The method sets the content type in the response object, content type will get set until response has not been committed.

Content Types: application/json, application/xml, etc.

boolean isCommitted() → This method will return true if response has been committed.

void setCharacterEncoding(String charset) → This method set the character encoding (MIME charset) in the response object. e.g. UTF-8

void setContentLength(int len) → This method set the length of the body content in the response object. This method sets the HTTP Content-Length inside response header.

void reset() → It will clear data, status code and headers from buffer.

void resetBuffer() → It will clear only data form buffer.

Imran Khan, Adobe Community Advisor, AEM certified developer and Java Geek, is an experienced AEM developer with over 11 years of expertise in designing and implementing robust web applications. He leverages Adobe Experience Manager, Analytics, and Target to create dynamic digital experiences. Imran possesses extensive expertise in J2EE, Sightly, Struts 2.0, Spring, Hibernate, JPA, React, HTML, jQuery, and JavaScript.

0