Extends the ServletResponse interface to provide HTTP-specific functionality in sending a response. For example, it has methods to access HTTP headers and cookies.

The servlet container creates an HttpServletResponse object and passes it as an argument to the servlet's service methods (doGet, doPost, etc).

Author

Various

See

javax.servlet.ServletResponse

Constructors

Methods

  • Returns the actual buffer size used for the response. If no buffering is used, this method returns 0.

    Returns number

    the actual buffer size used

    See

    • #setBufferSize
    • #flushBuffer
    • #isCommitted
    • #reset
  • Returns the name of the character encoding (MIME charset) used for the body sent in this response. The character encoding may have been specified explicitly using the #setCharacterEncoding or #setContentType methods, or implicitly using the #setLocale method. Explicit specifications take precedence over implicit specifications. Calls made to these methods after getWriter has been called or after the response has been committed have no effect on the character encoding. If no character encoding has been specified, ISO-8859-1 is returned. See RFC 2047 (http://www.ietf.org/rfc/rfc2047.txt) for more information about character encoding and MIME.

    Returns string

    a String specifying the name of the character encoding, for example, UTF-8

  • Returns the content type used for the MIME body sent in this response. The content type proper must have been specified using #setContentType before the response is committed. If no content type has been specified, this method returns null. If a content type has been specified, and a character encoding has been explicitly or implicitly specified as described in #getCharacterEncoding or #getWriter has been called, the charset parameter is included in the string returned. If no character encoding has been specified, the charset parameter is omitted.

    Returns string

    a String specifying the content type, for example, text/html; charset=UTF-8, or null

    Since

    Servlet 2.4

  • Gets the value of the response header with the given name.

    If a response header with the given name exists and contains multiple values, the value that was added first will be returned.

    This method considers only response headers set or added via #setHeader, #addHeader, #setDateHeader, #addDateHeader, #setIntHeader, or #addIntHeader, respectively.

    Parameters

    • name: string

      the name of the response header whose value to return

    Returns string

    the value of the response header with the given name, or null if no header with the given name has been set on this response

    Since

    Servlet 3.0

  • Gets the names of the headers of this response.

    This method considers only response headers set or added via #setHeader, #addHeader, #setDateHeader, #addDateHeader, #setIntHeader, or #addIntHeader, respectively.

    Any changes to the returned Collection must not affect this HttpServletResponse.

    Returns Collection<string>

    a (possibly empty) Collection of the names of the headers of this response

    Since

    Servlet 3.0

  • Gets the values of the response header with the given name.

    This method considers only response headers set or added via #setHeader, #addHeader, #setDateHeader, #addDateHeader, #setIntHeader, or #addIntHeader, respectively.

    Any changes to the returned Collection must not affect this HttpServletResponse.

    Parameters

    • name: string

      the name of the response header whose values to return

    Returns Collection<string>

    a (possibly empty) Collection of the values of the response header with the given name

    Since

    Servlet 3.0

  • Returns a ServletOutputStream suitable for writing binary data in the response. The servlet container does not encode the binary data.

    Calling flush() on the ServletOutputStream commits the response.

    Either this method or #getWriter may be called to write the body, not both, except when #reset has been called.

    Returns ServletOutputStream

    a ServletOutputStream for writing binary data

    Exception

    IllegalStateException if the getWriter method has been called on this response

    Exception

    IOException if an input or output exception occurred

    See

    • #getWriter
    • #reset
  • Returns a PrintWriter object that can send character text to the client. The PrintWriter uses the character encoding returned by #getCharacterEncoding. If the response's character encoding has not been specified as described in getCharacterEncoding (i.e., the method just returns the default value ISO-8859-1), getWriter updates it to ISO-8859-1. Calling flush() on the PrintWriter commits the response. Either this method or #getOutputStream may be called to write the body, not both, except when #reset has been called.

    Returns PrintWriter

    a PrintWriter object that can return character data to the client

    Exception

    java.io.UnsupportedEncodingException if the character encoding returned by getCharacterEncoding cannot be used

    Exception

    IllegalStateException if the getOutputStream method has already been called for this response object

    Exception

    IOException if an input or output exception occurred

    See

    • #getOutputStream
    • #setCharacterEncoding
    • #reset
  • Returns a boolean indicating if the response has been committed. A committed response has already had its status code and headers written.

    Returns boolean

    a boolean indicating if the response has been committed

    See

    • #setBufferSize
    • #getBufferSize
    • #flushBuffer
    • #reset