SE452: HTTP Response API [13/20] ![]() ![]() ![]() |
The server communicates with the client via response headers. These
are set via the response API. In class HttpServletResponse:
public void setContentLength( int len)
Sets the Content-Length header.
public void setContentType( String type)
Sets the Content-Type header.
public void setStatus( int statusCode)
Sets the status code for this response. This method is used to set the return status code when there is no error, e. g., SC_OK or SC_MOVED_TEMPORARILY . Should set status before sending document.
public void sendError( int statusCode) public void sendError( int statusCode,String message)
Sends an error response to the client using the specified status code and an (optional) descriptive message. Wraps the message inside a small HTML document.
public void sendRedirect( String location)
Sends a temporary redirect response to the client using the specified URL. May specify relative URL.
public boolean containsHeader( String name)
Whether the named response header has already been set.
public void setHeader( String name, String value)
Sets a response header with the given name and value. If the header is already set, the new value overwrites the previous one.
public void addHeader( String name, String value)
Adds a response header with the given name and value. Response headers may have multiple values.
public void setDateHeader( String name, long date) public void setIntHeader( String name, int value)
Sets a response header with the given name and date or integer value.
public void addDateHeader( String name, long date) public void addIntHeader( String name, int value)
Adds a response header with the given name and date or integer value.