javax.servlet.http
Interface HttpServletResponse

All Superinterfaces:
ServletResponse
All Known Subinterfaces:
CauchoResponse
All Known Implementing Classes:
AbstractCauchoResponse, CauchoResponseWrapper, CauchoResponseWrapper, DispatchResponse, HttpServletResponseImpl, HttpServletResponseWrapper, IncludeResponse, JspResponse, JspResponseWrapper, ProxyCacheResponse, ResponseAdapter, StubServletResponse, ToCharResponseAdapter

public interface HttpServletResponse
extends ServletResponse

HttpServletResponse extends ServletResponse allowing servlets to set the status and headers.

Useful Headers

Expires Lets clients cache the page. Resin can use Expires to internally cache the page.


Field Summary
static int SC_ACCEPTED
           
static int SC_BAD_GATEWAY
           
static int SC_BAD_REQUEST
           
static int SC_CONFLICT
           
static int SC_CONTINUE
           
static int SC_CREATED
           
static int SC_EXPECTATION_FAILED
           
static int SC_FORBIDDEN
           
static int SC_FOUND
           
static int SC_GATEWAY_TIMEOUT
           
static int SC_GONE
           
static int SC_HTTP_VERSION_NOT_SUPPORTED
           
static int SC_INTERNAL_SERVER_ERROR
           
static int SC_LENGTH_REQUIRED
           
static int SC_METHOD_NOT_ALLOWED
           
static int SC_MOVED_PERMANENTLY
           
static int SC_MOVED_TEMPORARILY
           
static int SC_MULTIPLE_CHOICES
           
static int SC_NO_CONTENT
           
static int SC_NON_AUTHORITATIVE_INFORMATION
           
static int SC_NOT_ACCEPTABLE
           
static int SC_NOT_FOUND
           
static int SC_NOT_IMPLEMENTED
           
static int SC_NOT_MODIFIED
           
static int SC_OK
           
static int SC_PARTIAL_CONTENT
           
static int SC_PAYMENT_REQUIRED
           
static int SC_PRECONDITION_FAILED
           
static int SC_PROXY_AUTHENTICATION_REQUIRED
           
static int SC_REQUEST_ENTITY_TOO_LARGE
           
static int SC_REQUEST_TIMEOUT
           
static int SC_REQUEST_URI_TOO_LONG
           
static int SC_REQUESTED_RANGE_NOT_SATISFIABLE
           
static int SC_RESET_CONTENT
           
static int SC_SEE_OTHER
           
static int SC_SERVICE_UNAVAILABLE
           
static int SC_SWITCHING_PROTOCOLS
           
static int SC_TEMPORARY_REDIRECT
           
static int SC_UNAUTHORIZED
           
static int SC_UNSUPPORTED_MEDIA_TYPE
           
static int SC_USE_PROXY
           
 
Method Summary
 void addCookie(Cookie cookie)
          Sends a new cookie to the client.
 void addDateHeader(java.lang.String name, long date)
          Adds a header by converting a date to a string.
 void addHeader(java.lang.String name, java.lang.String value)
          Adds a header.
 void addIntHeader(java.lang.String name, int value)
          Adds a header by converting an integer value to a string.
 boolean containsHeader(java.lang.String name)
          Returns true if the output headers include name
 java.lang.String encodeRedirectUrl(java.lang.String url)
          Deprecated.  
 java.lang.String encodeRedirectURL(java.lang.String name)
          Encodes session information in a URL suitable for sendRedirect()
 java.lang.String encodeUrl(java.lang.String url)
          Deprecated.  
 java.lang.String encodeURL(java.lang.String url)
          Encodes session information in a URL.
 java.lang.String getHeader(java.lang.String name)
          Retuns value of header with a given name
 java.util.Collection<java.lang.String> getHeaderNames()
          Returns an Iterable for header names set via setHeader(java.lang.String, java.lang.String), addHeader(java.lang.String, java.lang.String), setDateHeader(java.lang.String, long), addDateHeader(java.lang.String, long), setIntHeader(java.lang.String, int), or addIntHeader(java.lang.String, int), respectively.
 java.util.Collection<java.lang.String> getHeaders(java.lang.String name)
          Returns an Iterable for header values with a given name
 int getStatus()
          Returns the current status code of this response
 void sendError(int sc)
          Sends an HTTP error page based on the status code
 void sendError(int sc, java.lang.String msg)
          Sends an HTTP error page based on the status code
 void sendRedirect(java.lang.String location)
          Redirects the client to another page.
 void setDateHeader(java.lang.String name, long date)
          Sets a header by converting a date to a string.
 void setHeader(java.lang.String name, java.lang.String value)
          Sets a header.
 void setIntHeader(java.lang.String name, int value)
          Sets a header by converting an integer value to a string.
 void setStatus(int sc)
          Sets the HTTP status
 void setStatus(int sc, java.lang.String msg)
          Deprecated.  
 
Methods inherited from interface javax.servlet.ServletResponse
flushBuffer, getBufferSize, getCharacterEncoding, getContentType, getLocale, getOutputStream, getWriter, isCommitted, reset, resetBuffer, setBufferSize, setCharacterEncoding, setContentLength, setContentType, setLocale
 

Field Detail

SC_ACCEPTED

static final int SC_ACCEPTED
See Also:
Constant Field Values

SC_BAD_GATEWAY

static final int SC_BAD_GATEWAY
See Also:
Constant Field Values

SC_BAD_REQUEST

static final int SC_BAD_REQUEST
See Also:
Constant Field Values

SC_CONFLICT

static final int SC_CONFLICT
See Also:
Constant Field Values

SC_CONTINUE

static final int SC_CONTINUE
See Also:
Constant Field Values

SC_CREATED

static final int SC_CREATED
See Also:
Constant Field Values

SC_EXPECTATION_FAILED

static final int SC_EXPECTATION_FAILED
See Also:
Constant Field Values

SC_FORBIDDEN

static final int SC_FORBIDDEN
See Also:
Constant Field Values

SC_GATEWAY_TIMEOUT

static final int SC_GATEWAY_TIMEOUT
See Also:
Constant Field Values

SC_GONE

static final int SC_GONE
See Also:
Constant Field Values

SC_HTTP_VERSION_NOT_SUPPORTED

static final int SC_HTTP_VERSION_NOT_SUPPORTED
See Also:
Constant Field Values

SC_INTERNAL_SERVER_ERROR

static final int SC_INTERNAL_SERVER_ERROR
See Also:
Constant Field Values

SC_LENGTH_REQUIRED

static final int SC_LENGTH_REQUIRED
See Also:
Constant Field Values

SC_METHOD_NOT_ALLOWED

static final int SC_METHOD_NOT_ALLOWED
See Also:
Constant Field Values

SC_MOVED_PERMANENTLY

static final int SC_MOVED_PERMANENTLY
See Also:
Constant Field Values

SC_MOVED_TEMPORARILY

static final int SC_MOVED_TEMPORARILY
See Also:
Constant Field Values

SC_FOUND

static final int SC_FOUND
See Also:
Constant Field Values

SC_MULTIPLE_CHOICES

static final int SC_MULTIPLE_CHOICES
See Also:
Constant Field Values

SC_NO_CONTENT

static final int SC_NO_CONTENT
See Also:
Constant Field Values

SC_NON_AUTHORITATIVE_INFORMATION

static final int SC_NON_AUTHORITATIVE_INFORMATION
See Also:
Constant Field Values

SC_NOT_ACCEPTABLE

static final int SC_NOT_ACCEPTABLE
See Also:
Constant Field Values

SC_NOT_FOUND

static final int SC_NOT_FOUND
See Also:
Constant Field Values

SC_NOT_IMPLEMENTED

static final int SC_NOT_IMPLEMENTED
See Also:
Constant Field Values

SC_NOT_MODIFIED

static final int SC_NOT_MODIFIED
See Also:
Constant Field Values

SC_OK

static final int SC_OK
See Also:
Constant Field Values

SC_PARTIAL_CONTENT

static final int SC_PARTIAL_CONTENT
See Also:
Constant Field Values

SC_PAYMENT_REQUIRED

static final int SC_PAYMENT_REQUIRED
See Also:
Constant Field Values

SC_PRECONDITION_FAILED

static final int SC_PRECONDITION_FAILED
See Also:
Constant Field Values

SC_PROXY_AUTHENTICATION_REQUIRED

static final int SC_PROXY_AUTHENTICATION_REQUIRED
See Also:
Constant Field Values

SC_REQUEST_ENTITY_TOO_LARGE

static final int SC_REQUEST_ENTITY_TOO_LARGE
See Also:
Constant Field Values

SC_REQUEST_TIMEOUT

static final int SC_REQUEST_TIMEOUT
See Also:
Constant Field Values

SC_REQUEST_URI_TOO_LONG

static final int SC_REQUEST_URI_TOO_LONG
See Also:
Constant Field Values

SC_REQUESTED_RANGE_NOT_SATISFIABLE

static final int SC_REQUESTED_RANGE_NOT_SATISFIABLE
See Also:
Constant Field Values

SC_RESET_CONTENT

static final int SC_RESET_CONTENT
See Also:
Constant Field Values

SC_SEE_OTHER

static final int SC_SEE_OTHER
See Also:
Constant Field Values

SC_SERVICE_UNAVAILABLE

static final int SC_SERVICE_UNAVAILABLE
See Also:
Constant Field Values

SC_SWITCHING_PROTOCOLS

static final int SC_SWITCHING_PROTOCOLS
See Also:
Constant Field Values

SC_UNAUTHORIZED

static final int SC_UNAUTHORIZED
See Also:
Constant Field Values

SC_UNSUPPORTED_MEDIA_TYPE

static final int SC_UNSUPPORTED_MEDIA_TYPE
See Also:
Constant Field Values

SC_USE_PROXY

static final int SC_USE_PROXY
See Also:
Constant Field Values

SC_TEMPORARY_REDIRECT

static final int SC_TEMPORARY_REDIRECT
See Also:
Constant Field Values
Method Detail

setStatus

void setStatus(int sc)
Sets the HTTP status

Parameters:
sc - the HTTP status code

sendError

void sendError(int sc,
               java.lang.String msg)
               throws java.io.IOException
Sends an HTTP error page based on the status code

Parameters:
sc - the HTTP status code
Throws:
java.io.IOException

sendError

void sendError(int sc)
               throws java.io.IOException
Sends an HTTP error page based on the status code

Parameters:
sc - the HTTP status code
Throws:
java.io.IOException

sendRedirect

void sendRedirect(java.lang.String location)
                  throws java.io.IOException
Redirects the client to another page.

Parameters:
location - the location to redirect to.
Throws:
java.io.IOException

setHeader

void setHeader(java.lang.String name,
               java.lang.String value)
Sets a header. This will override a previous header with the same name.

Parameters:
name - the header name
value - the header value

addHeader

void addHeader(java.lang.String name,
               java.lang.String value)
Adds a header. If another header with the same name exists, both will be sent to the client.

Parameters:
name - the header name
value - the header value

containsHeader

boolean containsHeader(java.lang.String name)
Returns true if the output headers include name

Parameters:
name - the header name to test

setDateHeader

void setDateHeader(java.lang.String name,
                   long date)
Sets a header by converting a date to a string.

To set the page to expire in 15 seconds use the following:


 long now = System.currentTime();
 response.setDateHeader("Expires", now + 15000);
 

Parameters:
name - name of the header
date - the date in milliseconds since the epoch.

addDateHeader

void addDateHeader(java.lang.String name,
                   long date)
Adds a header by converting a date to a string.

Parameters:
name - name of the header
date - the date in milliseconds since the epoch.

setIntHeader

void setIntHeader(java.lang.String name,
                  int value)
Sets a header by converting an integer value to a string.

Parameters:
name - name of the header
value - the value as an integer

addIntHeader

void addIntHeader(java.lang.String name,
                  int value)
Adds a header by converting an integer value to a string.

Parameters:
name - name of the header
value - the value as an integer

addCookie

void addCookie(Cookie cookie)
Sends a new cookie to the client.


encodeURL

java.lang.String encodeURL(java.lang.String url)
Encodes session information in a URL. Calling this will enable sessions for users who have disabled cookies.

Parameters:
url - the url to encode
Returns:
a url with session information encoded

encodeRedirectURL

java.lang.String encodeRedirectURL(java.lang.String name)
Encodes session information in a URL suitable for sendRedirect()

Parameters:
name - the url to encode
Returns:
a url with session information encoded

setStatus

void setStatus(int sc,
               java.lang.String msg)
Deprecated. 


encodeUrl

java.lang.String encodeUrl(java.lang.String url)
Deprecated. 


encodeRedirectUrl

java.lang.String encodeRedirectUrl(java.lang.String url)
Deprecated. 


getStatus

int getStatus()
Returns the current status code of this response

Returns:

getHeader

java.lang.String getHeader(java.lang.String name)
Retuns value of header with a given name

Parameters:
name -
Returns:

getHeaders

java.util.Collection<java.lang.String> getHeaders(java.lang.String name)
Returns an Iterable for header values with a given name

Parameters:
name -
Returns:

getHeaderNames

java.util.Collection<java.lang.String> getHeaderNames()
Returns an Iterable for header names set via setHeader(java.lang.String, java.lang.String), addHeader(java.lang.String, java.lang.String), setDateHeader(java.lang.String, long), addDateHeader(java.lang.String, long), setIntHeader(java.lang.String, int), or addIntHeader(java.lang.String, int), respectively.

Returns: