Interface: javax.servlet.ServletResponse

  • public interface ServletResponse
Defines an object to assist a servlet in sending a response to the client. The servlet container creates a ServletResponse object and passes it as an argument to the servlet's service method.

To send binary data in a MIME body response, use the javax.servlet.ServletOutputStream returned by javax.servlet.ServletResponse.getOutputStream(). To send character data, use the PrintWriter object returned by javax.servlet.ServletResponse.getWriter(). To mix binary and text data, for example, to create a multipart response, use a ServletOutputStream and manage the character sections manually.

The charset for the MIME body response can be specified explicitly using the javax.servlet.ServletResponse.setCharacterEncoding(java.lang.String) and javax.servlet.ServletResponse.setContentType(java.lang.String) methods, or implicitly using the javax.servlet.ServletResponse.setLocale(java.util.Locale) method. Explicit specifications take precedence over implicit specifications. If no charset is specified, ISO-8859-1 will be used. The setCharacterEncoding, setContentType, or setLocale method must be called before getWriter and before committing the response for the character encoding to be used.

See the Internet RFCs such as RFC 2045 for more information on MIME. Protocols such as SMTP and HTTP define profiles of MIME, and those standards are still evolving.

Authors:
@author Various
See:
@see javax.servlet.ServletOutputStream

Methods