HttpServletResponse

HttpServletResponse interface belongs to javax.servlet package and extends ServletResponse interface. It 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


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

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.

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

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

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

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

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

void setContentType(String type) → The method sets the content type until response didn’t get commit.
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 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

Specialist Master (Architect) with a passion for cutting-edge technologies like AEM (Adobe Experience Manager) and a proven track record of delivering high-quality software solutions.

  • Languages: Java, Python
  • Frameworks: J2EE, Spring, Struts 2.0, Hibernate
  • Web Technologies: React, HTML, CSS
  • Analytics: Adobe Analytics
  • Tools & Technologies: IntelliJ, JIRA

🌐 LinkedIn

📝 Blogs

📧 Imran Khan