Skip to Main Content
Java Servlet Programming
book

Java Servlet Programming

by Jason Hunter
November 1998
Intermediate to advanced content levelIntermediate to advanced
526 pages
14h 38m
English
O'Reilly Media, Inc.
Content preview from Java Servlet Programming

Name

ServletResponse

Synopsis

Interface Name: javax.servlet.ServletResponse

Superinterface: None

Immediate Subinterfaces: javax.servlet.http.HttpServletResponse

Interfaces Implemented: None

Availability: Servlet API 1.0 and later

Description

Servlets use ServletResponse objects to send MIME encoded data back to the client. The servlet engine creates this object and passes it to the servlet’s service() method. To send binary data, use the ServletOutputStream returned by getOutputStream(). To send character data, use the PrintWriter returned by getWriter(). You can explicitly set the output’s MIME type using the setContentType() method. If you elect to set this manually, do so before calling getWriter(), as getWriter() consults the content type to determine which charset to use. Consult RFC 2045 at http://www.ietf.org/rfc/rfc2045.txt for more information on MIME.

Interface Declaration

public interface ServletResponse {
  // Methods
  public abstract String getCharacterEncoding();               // New in 2.0
  public abstract ServletOutputStream getOutputStream() throws IOException;
  public abstract PrintWriter getWriter() throws IOException;  // New in 2.0
  public abstract void setContentLength(int len);
  public abstract void setContentType(String type);
}

Methods

getCharacterEncoding()

public abstract String getCharacterEncoding()
Description

Returns the charset encoding used for this MIME body. This is the charset specified by the assigned content type or "ISO-8859-1" if no charset has been specified. This method was ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Java Servlet Programming, 2nd Edition

Java Servlet Programming, 2nd Edition

Jason Hunter, William Crawford

Publisher Resources

ISBN: 156592391XSupplemental ContentCatalog PageErrata