Interface ServletResponse

All Known Subinterfaces:
HttpServletResponse
All Known Implementing Classes:
HttpServletResponseWrapper, ServletResponseWrapper

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 ServletOutputStream returned by getOutputStream(). To send character data, use the PrintWriter object returned by 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 or implicitly. The priority order for specifying the response body is:

  1. explicitly per request using setCharacterEncoding(java.lang.String) and setContentType(java.lang.String)
  2. implicitly per request using setLocale(java.util.Locale)
  3. per web application via the deployment descriptor or ServletContext.setRequestCharacterEncoding(String)
  4. container default via vendor specific configuration
  5. ISO-8859-1
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.

See Also: