Top Description Inners Fields Constructors Methods
org.mortbay.jetty

public Class Response

extends Object
implements HttpServletResponse
Class Inheritance
All Implemented Interfaces
javax.servlet.http.HttpServletResponse, javax.servlet.ServletResponse
Imports
java.io.IOException, .PrintWriter, java.util.Collections, .Enumeration, .Locale, javax.servlet.ServletOutputStream, javax.servlet.http.Cookie, .HttpServletResponse, .HttpSession, org.mortbay.io.BufferCache.CachedBuffer, org.mortbay.jetty.handler.ContextHandler, .ErrorHandler, org.mortbay.jetty.servlet.ServletHandler, org.mortbay.log.Log, org.mortbay.util.ByteArrayISO8859Writer, .IO, .QuotedStringTokenizer, .StringUtil, .URIUtil

Response.

Implements javax.servlet.HttpServletResponse from the javax.servlet package.

Author
gregw

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private static PrintWriter
private static ServletOutputStream
private BufferCache.CachedBuffer
private String
private HttpConnection
private String
private boolean
private int
private boolean
private Locale
private String
private int
private String
private int
private PrintWriter
public static final int
public static final int
public static String
SET_INCLUDE_HEADER_PREFIX

If a header name starts with this string, the header (stripped of the prefix) can be set during include using only setHeader(String, String) or addHeader(String, String).

public static final int
public static final int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
addCookie(Cookie
the Cookie to return to the client
cookie
)

Implements javax.servlet.http.HttpServletResponse.addCookie.

Adds the specified cookie to the response.
public void
addDateHeader(String
the name of the header to set
name
,
long
the additional date value
date
)

Implements javax.servlet.http.HttpServletResponse.addDateHeader.

Adds a response header with the given name and date-value.
public void
addHeader(String
the name of the header
name
,
String
the additional header value If it contains octet string, it should be encoded according to RFC 2047 (http://www.ietf.org/rfc/rfc2047.txt)
value
)

Implements javax.servlet.http.HttpServletResponse.addHeader.

Adds a response header with the given name and value.
public void
addIntHeader(String
the name of the header
name
,
int
the assigned integer value
value
)

Implements javax.servlet.http.HttpServletResponse.addIntHeader.

Adds a response header with the given name and integer value.
public void
public boolean
containsHeader(String
the header name
name
)

Implements javax.servlet.http.HttpServletResponse.containsHeader.

Returns a boolean indicating whether the named response header has already been set.
public void
public void
public String
encodeRedirectURL(String
the url to be encoded.
url
)

Implements javax.servlet.http.HttpServletResponse.encodeRedirectURL.

Encodes the specified URL for use in the sendRedirect method or, if encoding is not needed, returns the URL unchanged.
public String
public String
encodeURL(String
the url to be encoded.
url
)

Implements javax.servlet.http.HttpServletResponse.encodeURL.

Encodes the specified URL by including the session ID, or, if encoding is not needed, returns the URL unchanged.
public String
public void
flushBuffer()

Implements javax.servlet.ServletResponse.flushBuffer.

Forces any content in the buffer to be written to the client.
public int
getBufferSize()

Implements javax.servlet.ServletResponse.getBufferSize.

Returns the actual buffer size used for the response.
public String
getCharacterEncoding()

Implements javax.servlet.ServletResponse.getCharacterEncoding.

Returns the name of the character encoding (MIME charset) used for the body sent in this response.
public long

Returns:

the number of bytes actually written in response body
getContentCount
()

public String
getContentType()

Implements javax.servlet.ServletResponse.getContentType.

Returns the content type used for the MIME body sent in this response.
public String
getHeader(String
the name of the response header whose value to return
name
)

Implements javax.servlet.http.HttpServletResponse.getHeader.

Gets the value of the response header with the given name.
public Enumeration<E>
getHeaders(String
the name of the response header whose values to return
name
)

Implements javax.servlet.http.HttpServletResponse.getHeaders.

Gets the values of the response header with the given name.
public HttpFields
public Locale
getLocale()

Implements javax.servlet.ServletResponse.getLocale.

Returns the locale specified for this response using the setLocale method.
public ServletOutputStream
getOutputStream()

Implements javax.servlet.ServletResponse.getOutputStream.

Returns a ServletOutputStream suitable for writing binary data in the response.
public String

Returns:

The reason associated with the current status. This will be null, unless one of the setStatus methods have been called.
getReason
()

public int

Returns:

The HTTP status code that has been set for this request. This will be 200 (HttpServletResponse#SC_OK), unless explicitly set through one of the setStatus methods.
getStatus
()

Implements javax.servlet.http.HttpServletResponse.getStatus.

Gets the current status code of this response.
public PrintWriter
getWriter()

Implements javax.servlet.ServletResponse.getWriter.

Returns a PrintWriter object that can send character text to the client.
public boolean
isCommitted()

Implements javax.servlet.ServletResponse.isCommitted.

Returns a boolean indicating if the response has been committed.
public boolean
public boolean
protected void
public void
reset()

Implements javax.servlet.ServletResponse.reset.

Clears any data that exists in the buffer as well as the status code, headers.
public void
resetBuffer()

Implements javax.servlet.ServletResponse.resetBuffer.

Clears the content of the underlying buffer in the response without clearing headers or status code.
public void
sendError(int
the error status code
code
,
String
the descriptive message
message
)

Implements javax.servlet.http.HttpServletResponse.sendError.

Sends an error response to the client using the specified status and clears the buffer.

public void
sendError(int
the error status code
sc
)

Implements javax.servlet.http.HttpServletResponse.sendError.

Sends an error response to the client using the specified status code and clears the buffer.
public void
public void
sendRedirect(String
the redirect location URL
location
)

Implements javax.servlet.http.HttpServletResponse.sendRedirect.

Sends a temporary redirect response to the client using the specified redirect location URL and clears the buffer.
public void
setBufferSize(int
the preferred buffer size
size
)

Implements javax.servlet.ServletResponse.setBufferSize.

Sets the preferred buffer size for the body of the response.
public void
setCharacterEncoding(String
a String specifying only the character set defined by IANA Character Sets (http://www.iana.org/assignments/character-sets)
encoding
)

Implements javax.servlet.ServletResponse.setCharacterEncoding.

Sets the character encoding (MIME charset) of the response being sent to the client, for example, to UTF-8.
public void
setContentLength(int
an integer specifying the length of the content being returned to the client; sets the Content-Length header
len
)

Implements javax.servlet.ServletResponse.setContentLength.

Sets the length of the content body in the response In HTTP servlets, this method sets the HTTP Content-Length header.
public void
setContentType(String
a String specifying the MIME type of the content
contentType
)

Implements javax.servlet.ServletResponse.setContentType.

Sets the content type of the response being sent to the client, if the response has not been committed yet.
public void
setDateHeader(String
the name of the header to set
name
,
long
the assigned date value
date
)

Implements javax.servlet.http.HttpServletResponse.setDateHeader.

Sets a response header with the given name and date-value.
public void
setHeader(String
the name of the header
name
,
String
the header value If it contains octet string, it should be encoded according to RFC 2047 (http://www.ietf.org/rfc/rfc2047.txt)
value
)

Implements javax.servlet.http.HttpServletResponse.setHeader.

Sets a response header with the given name and value.
public void
setIntHeader(String
the name of the header
name
,
int
the assigned integer value
value
)

Implements javax.servlet.http.HttpServletResponse.setIntHeader.

Sets a response header with the given name and integer value.
public void
setLocale(Locale
the locale of the response
locale
)

Implements javax.servlet.ServletResponse.setLocale.

Sets the locale of the response, if the response has not been committed yet.
public void
public void
setStatus(int
the status code
sc
)

Implements javax.servlet.http.HttpServletResponse.setStatus.

Sets the status code for this response.
public void
setStatus(int
the status code
sc
,
String
the status message
sm
)

Implements javax.servlet.http.HttpServletResponse.setStatus.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

__nullPrintWriterback to summary
private static PrintWriter __nullPrintWriter
__nullServletOutback to summary
private static ServletOutputStream __nullServletOut
_cachedMimeTypeback to summary
private BufferCache.CachedBuffer _cachedMimeType
_characterEncodingback to summary
private String _characterEncoding
_connectionback to summary
private HttpConnection _connection
_contentTypeback to summary
private String _contentType
_disabledback to summary
private boolean _disabled
_disabledOutputStateback to summary
private int _disabledOutputState
_explicitEncodingback to summary
private boolean _explicitEncoding
_localeback to summary
private Locale _locale
_mimeTypeback to summary
private String _mimeType
_outputStateback to summary
private int _outputState
_reasonback to summary
private String _reason
_statusback to summary
private int _status
_writerback to summary
private PrintWriter _writer
DISABLEDback to summary
public static final int DISABLED
NONEback to summary
public static final int NONE
SET_INCLUDE_HEADER_PREFIXback to summary
public static String SET_INCLUDE_HEADER_PREFIX

If a header name starts with this string, the header (stripped of the prefix) can be set during include using only setHeader(String, String) or addHeader(String, String).

STREAMback to summary
public static final int STREAM
WRITERback to summary
public static final int WRITER

Constructor Detail

Responseback to summary
public Response(HttpConnection connection)

Method Detail

addCookieback to summary
public void addCookie(Cookie cookie)

Implements javax.servlet.http.HttpServletResponse.addCookie.

Doc from javax.servlet.http.HttpServletResponse.addCookie.

Adds the specified cookie to the response. This method can be called multiple times to set more than one cookie.

Parameters
cookie:Cookie

the Cookie to return to the client

addDateHeaderback to summary
public void addDateHeader(String name, long date)

Implements javax.servlet.http.HttpServletResponse.addDateHeader.

Doc from javax.servlet.http.HttpServletResponse.addDateHeader.

Adds a response header with the given name and date-value. The date is specified in terms of milliseconds since the epoch. This method allows response headers to have multiple values.

Parameters
name:String

the name of the header to set

date:long

the additional date value

addHeaderback to summary
public void addHeader(String name, String value)

Implements javax.servlet.http.HttpServletResponse.addHeader.

Doc from javax.servlet.http.HttpServletResponse.addHeader.

Adds a response header with the given name and value. This method allows response headers to have multiple values.

Parameters
name:String

the name of the header

value:String

the additional header value If it contains octet string, it should be encoded according to RFC 2047 (http://www.ietf.org/rfc/rfc2047.txt)

addIntHeaderback to summary
public void addIntHeader(String name, int value)

Implements javax.servlet.http.HttpServletResponse.addIntHeader.

Doc from javax.servlet.http.HttpServletResponse.addIntHeader.

Adds a response header with the given name and integer value. This method allows response headers to have multiple values.

Parameters
name:String

the name of the header

value:int

the assigned integer value

completeback to summary
public void complete() throws IOException
containsHeaderback to summary
public boolean containsHeader(String name)

Implements javax.servlet.http.HttpServletResponse.containsHeader.

Doc from javax.servlet.http.HttpServletResponse.containsHeader.

Returns a boolean indicating whether the named response header has already been set.

Parameters
name:String

the header name

Returns:boolean

true if the named response header has already been set; false otherwise

disableback to summary
public void disable()
enableback to summary
public void enable()
encodeRedirectURLback to summary
public String encodeRedirectURL(String url)

Implements javax.servlet.http.HttpServletResponse.encodeRedirectURL.

Doc from javax.servlet.http.HttpServletResponse.encodeRedirectURL.

Encodes the specified URL for use in the sendRedirect method or, if encoding is not needed, returns the URL unchanged. The implementation of this method includes the logic to determine whether the session ID needs to be encoded in the URL. For example, if the browser supports cookies, or session tracking is turned off, URL encoding is unnecessary. Because the rules for making this determination can differ from those used to decide whether to encode a normal link, this method is separated from the encodeURL method.

All URLs sent to the HttpServletResponse.sendRedirect method should be run through this method. Otherwise, URL rewriting cannot be used with browsers which do not support cookies.

If the URL is relative, it is always relative to the current HttpServletRequest.

Parameters
url:String

the url to be encoded.

Returns:String

the encoded URL if encoding is needed; the unchanged URL otherwise.

encodeRedirectUrlback to summary
public String encodeRedirectUrl(String url)

Implements javax.servlet.http.HttpServletResponse.encodeRedirectUrl.

Parameters
url:String

Doc from javax.servlet.http.HttpServletResponse.encodeRedirectUrl.

the url to be encoded.

Returns:String

Doc from javax.servlet.http.HttpServletResponse.encodeRedirectUrl.

the encoded URL if encoding is needed; the unchanged URL otherwise.

encodeURLback to summary
public String encodeURL(String url)

Implements javax.servlet.http.HttpServletResponse.encodeURL.

Doc from javax.servlet.http.HttpServletResponse.encodeURL.

Encodes the specified URL by including the session ID, or, if encoding is not needed, returns the URL unchanged. The implementation of this method includes the logic to determine whether the session ID needs to be encoded in the URL. For example, if the browser supports cookies, or session tracking is turned off, URL encoding is unnecessary.

For robust session tracking, all URLs emitted by a servlet should be run through this method. Otherwise, URL rewriting cannot be used with browsers which do not support cookies.

If the URL is relative, it is always relative to the current HttpServletRequest.

Parameters
url:String

the url to be encoded.

Returns:String

the encoded URL if encoding is needed; the unchanged URL otherwise.

encodeUrlback to summary
public String encodeUrl(String url)

Implements javax.servlet.http.HttpServletResponse.encodeUrl.

Parameters
url:String

Doc from javax.servlet.http.HttpServletResponse.encodeUrl.

the url to be encoded.

Returns:String

Doc from javax.servlet.http.HttpServletResponse.encodeUrl.

the encoded URL if encoding is needed; the unchanged URL otherwise.

flushBufferback to summary
public void flushBuffer() throws IOException

Implements javax.servlet.ServletResponse.flushBuffer.

Doc from javax.servlet.ServletResponse.flushBuffer.

Forces any content in the buffer to be written to the client. A call to this method automatically commits the response, meaning the status code and headers will be written.

Exceptions
IOException:
if the act of flushing the buffer cannot be completed.
getBufferSizeback to summary
public int getBufferSize()

Implements javax.servlet.ServletResponse.getBufferSize.

Doc from javax.servlet.ServletResponse.getBufferSize.

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

Returns:int

the actual buffer size used

getCharacterEncodingback to summary
public String getCharacterEncoding()

Implements javax.servlet.ServletResponse.getCharacterEncoding.

Doc from javax.servlet.ServletResponse.getCharacterEncoding.

Returns the name of the character encoding (MIME charset) used for the body sent in this response. The following methods for specifying the response character encoding are consulted, in decreasing order of priority: per request, perweb-app (using ServletContext#setResponseCharacterEncoding, deployment descriptor), and per container (for all web applications deployed in that container, using vendor specific configuration). The first one of these methods that yields a result is returned. Per-request, the charset for the response can be specified explicitly using the setCharacterEncoding and setContentType methods, or implicitly using the setLocale(java.util.Locale) 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

getContentCountback to summary
public long getContentCount()
Returns:long

the number of bytes actually written in response body

getContentTypeback to summary
public String getContentType()

Implements javax.servlet.ServletResponse.getContentType.

Doc from javax.servlet.ServletResponse.getContentType.

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

getHeaderback to summary
public String getHeader(String name)

Implements javax.servlet.http.HttpServletResponse.getHeader.

Doc from javax.servlet.http.HttpServletResponse.getHeader.

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

getHeadersback to summary
public Enumeration<E> getHeaders(String name)

Implements javax.servlet.http.HttpServletResponse.getHeaders.

Doc from javax.servlet.http.HttpServletResponse.getHeaders.

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:Enumeration<E>

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

getHttpFieldsback to summary
public HttpFields getHttpFields()
getLocaleback to summary
public Locale getLocale()

Implements javax.servlet.ServletResponse.getLocale.

Doc from javax.servlet.ServletResponse.getLocale.

Returns the locale specified for this response using the setLocale method. Calls made to setLocale after the response is committed have no effect. If no locale has been specified, the container's default locale is returned.

Returns:Locale

the Locale for this response.

getOutputStreamback to summary
public ServletOutputStream getOutputStream() throws IOException

Implements javax.servlet.ServletResponse.getOutputStream.

Doc from javax.servlet.ServletResponse.getOutputStream.

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

Exceptions
IOException:
if an input or output exception occurred
getReasonback to summary
public String getReason()
Returns:String

The reason associated with the current status. This will be null, unless one of the setStatus methods have been called.

getStatusback to summary
public int getStatus()

Implements javax.servlet.http.HttpServletResponse.getStatus.

Doc from javax.servlet.http.HttpServletResponse.getStatus.

Gets the current status code of this response.

Returns:int

The HTTP status code that has been set for this request. This will be 200 (HttpServletResponse#SC_OK), unless explicitly set through one of the setStatus methods.

getWriterback to summary
public PrintWriter getWriter() throws IOException

Implements javax.servlet.ServletResponse.getWriter.

Doc from javax.servlet.ServletResponse.getWriter.

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

Exceptions
IOException:
if an input or output exception occurred
isCommittedback to summary
public boolean isCommitted()

Implements javax.servlet.ServletResponse.isCommitted.

Doc from javax.servlet.ServletResponse.isCommitted.

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

isDisabledback to summary
public boolean isDisabled()
isWritingback to summary
public boolean isWriting()
recycleback to summary
protected void recycle()
resetback to summary
public void reset()

Implements javax.servlet.ServletResponse.reset.

Doc from javax.servlet.ServletResponse.reset.

Clears any data that exists in the buffer as well as the status code, headers. The state of calling getWriter or getOutputStream is also cleared. It is legal, for instance, to call getWriter, reset and then getOutputStream. If getWriter or getOutputStream have been called before this method, then the corrresponding returned Writer or OutputStream will be staled and the behavior of using the stale object is undefined. If the response has been committed, this method throws an IllegalStateException.

resetBufferback to summary
public void resetBuffer()

Implements javax.servlet.ServletResponse.resetBuffer.

Doc from javax.servlet.ServletResponse.resetBuffer.

Clears the content of the underlying buffer in the response without clearing headers or status code. If the response has been committed, this method throws an IllegalStateException.

sendErrorback to summary
public void sendError(int code, String message) throws IOException

Implements javax.servlet.http.HttpServletResponse.sendError.

Doc from javax.servlet.http.HttpServletResponse.sendError.

Sends an error response to the client using the specified status and clears the buffer. The server defaults to creating the response to look like an HTML-formatted server error page containing the specified message, setting the content type to "text/html". The caller is not responsible for escaping or re-encoding the message to ensure it is safe with respect to the current response encoding and content type. This aspect of safety is the responsibility of the container, as it is generating the error page containing the message. The server will preserve cookies and may clear or update any headers needed to serve the error page as a valid response.

If an error-page declaration has been made for the web application corresponding to the status code passed in, it will be served back in preference to the suggested msg parameter and the msg parameter will be ignored.

If the response has already been committed, this method throws an IllegalStateException. After using this method, the response should be considered to be committed and should not be written to.

Parameters
code:int

the error status code

message:String

the descriptive message

Exceptions
IOException:
If an input or output exception occurs
sendErrorback to summary
public void sendError(int sc) throws IOException

Implements javax.servlet.http.HttpServletResponse.sendError.

Doc from javax.servlet.http.HttpServletResponse.sendError.

Sends an error response to the client using the specified status code and clears the buffer. The server will preserve cookies and may clear or update any headers needed to serve the error page as a valid response. If an error-page declaration has been made for the web application corresponding to the status code passed in, it will be served back the error page

If the response has already been committed, this method throws an IllegalStateException. After using this method, the response should be considered to be committed and should not be written to.

Parameters
sc:int

the error status code

Exceptions
IOException:
If an input or output exception occurs
sendProcessingback to summary
public void sendProcessing() throws IOException
sendRedirectback to summary
public void sendRedirect(String location) throws IOException

Implements javax.servlet.http.HttpServletResponse.sendRedirect.

Doc from javax.servlet.http.HttpServletResponse.sendRedirect.

Sends a temporary redirect response to the client using the specified redirect location URL and clears the buffer. The buffer will be replaced with the data set by this method. Calling this method sets the status code to SC_FOUND 302 (Found). This method can accept relative URLs;the servlet container must convert the relative URL to an absolute URL before sending the response to the client. If the location is relative without a leading '/' the container interprets it as relative to the current request URI. If the location is relative with a leading '/' the container interprets it as relative to the servlet container root. If the location is relative with two leading '/' the container interprets it as a network-path reference (see RFC 3986: Uniform Resource Identifier (URI): Generic Syntax, section 4.2 "Relative Reference").

If the response has already been committed, this method throws an IllegalStateException. After using this method, the response should be considered to be committed and should not be written to.

Parameters
location:String

the redirect location URL

Exceptions
IOException:
If an input or output exception occurs
setBufferSizeback to summary
public void setBufferSize(int size)

Implements javax.servlet.ServletResponse.setBufferSize.

Doc from javax.servlet.ServletResponse.setBufferSize.

Sets the preferred buffer size for the body of the response. The servlet container will use a buffer at least as large as the size requested. The actual buffer size used can be found using getBufferSize.

A larger buffer allows more content to be written before anything is actually sent, thus providing the servlet with more time to set appropriate status codes and headers. A smaller buffer decreases server memory load and allows the client to start receiving data more quickly.

This method must be called before any response body content is written; if content has been written or the response object has been committed, this method throws an IllegalStateException.

Parameters
size:int

the preferred buffer size

setCharacterEncodingback to summary
public void setCharacterEncoding(String encoding)

Implements javax.servlet.ServletResponse.setCharacterEncoding.

Doc from javax.servlet.ServletResponse.setCharacterEncoding.

Sets the character encoding (MIME charset) of the response being sent to the client, for example, to UTF-8. If the response character encoding has already been set by the ServletContext#setResponseCharacterEncoding, deployment descriptor, or using the setContentType() or setLocale() methods, the value set in this method overrides any of those values. Calling setContentType with the String of text/html and calling this method with the String of UTF-8 is equivalent with calling setContentType with the String of text/html; charset=UTF-8.

This method can be called repeatedly to change the character encoding. This method has no effect if it is called after getWriter has been called or after the response has been committed.

Containers must communicate the character encoding used for the servlet response's writer to the client if the protocol provides a way for doing so. In the case of HTTP, the character encoding is communicated as part of the Content-Type header for text media types. Note that the character encoding cannot be communicated via HTTP headers if the servlet does not specify a content type; however, it is still used to encode text written via the servlet response's writer.

Parameters
encoding:String

a String specifying only the character set defined by IANA Character Sets (http://www.iana.org/assignments/character-sets)

setContentLengthback to summary
public void setContentLength(int len)

Implements javax.servlet.ServletResponse.setContentLength.

Doc from javax.servlet.ServletResponse.setContentLength.

Sets the length of the content body in the response In HTTP servlets, this method sets the HTTP Content-Length header.

Parameters
len:int

an integer specifying the length of the content being returned to the client; sets the Content-Length header

setContentTypeback to summary
public void setContentType(String contentType)

Implements javax.servlet.ServletResponse.setContentType.

Doc from javax.servlet.ServletResponse.setContentType.

Sets the content type of the response being sent to the client, if the response has not been committed yet. The given content type may include a character encoding specification, for example, text/html;charset=UTF-8. The response's character encoding is only set from the given content type if this method is called before getWriter is called.

This method may be called repeatedly to change content type and character encoding. This method has no effect if called after the response has been committed. It does not set the response's character encoding if it is called after getWriter has been called or after the response has been committed.

Containers must communicate the content type and the character encoding used for the servlet response's writer to the client if the protocol provides a way for doing so. In the case of HTTP, the Content-Type header is used.

Parameters
contentType:String

a String specifying the MIME type of the content

setDateHeaderback to summary
public void setDateHeader(String name, long date)

Implements javax.servlet.http.HttpServletResponse.setDateHeader.

Doc from javax.servlet.http.HttpServletResponse.setDateHeader.

Sets a response header with the given name and date-value. The date is specified in terms of milliseconds since the epoch. If the header had already been set, the new value overwrites the previous one. The containsHeader method can be used to test for the presence of a header before setting its value.

Parameters
name:String

the name of the header to set

date:long

the assigned date value

setHeaderback to summary
public void setHeader(String name, String value)

Implements javax.servlet.http.HttpServletResponse.setHeader.

Doc from javax.servlet.http.HttpServletResponse.setHeader.

Sets a response header with the given name and value. If the header had already been set, the new value overwrites the previous one. The containsHeader method can be used to test for the presence of a header before setting its value.

Parameters
name:String

the name of the header

value:String

the header value If it contains octet string, it should be encoded according to RFC 2047 (http://www.ietf.org/rfc/rfc2047.txt)

setIntHeaderback to summary
public void setIntHeader(String name, int value)

Implements javax.servlet.http.HttpServletResponse.setIntHeader.

Doc from javax.servlet.http.HttpServletResponse.setIntHeader.

Sets a response header with the given name and integer value. If the header had already been set, the new value overwrites the previous one. The containsHeader method can be used to test for the presence of a header before setting its value.

Parameters
name:String

the name of the header

value:int

the assigned integer value

setLocaleback to summary
public void setLocale(Locale locale)

Implements javax.servlet.ServletResponse.setLocale.

Doc from javax.servlet.ServletResponse.setLocale.

Sets the locale of the response, if the response has not been committed yet. It also sets the response's character encoding appropriately for the locale, if the character encoding has not been explicitly set using setContentType or setCharacterEncoding, getWriter hasn't been called yet, and the response hasn't been committed yet. If the deployment descriptor contains a locale-encoding-mapping-list element, and that element provides a mapping for the given locale, that mapping is used. Otherwise, the mapping from locale to character encoding is container dependent.

This method may be called repeatedly to change locale and character encoding. The method has no effect if called after the response has been committed. It does not set the response's character encoding if it is called after setContentType has been called with a charset specification, after setCharacterEncoding has been called, after getWriter has been called, or after the response has been committed.

Containers must communicate the locale and the character encoding used for the servlet response's writer to the client if the protocol provides a way for doing so. In the case of HTTP, the locale is communicated via the Content-Language header, the character encoding as part of the Content-Type header for text media types. Note that the character encoding cannot be communicated via HTTP headers if the servlet does not specify a content type; however, it is still used to encode text written via the servlet response's writer.

Parameters
locale:Locale

the locale of the response

setLongContentLengthback to summary
public void setLongContentLength(long len)
setStatusback to summary
public void setStatus(int sc)

Implements javax.servlet.http.HttpServletResponse.setStatus.

Doc from javax.servlet.http.HttpServletResponse.setStatus.

Sets the status code for this response.

This method is used to set the return status code when there is no error (for example, for the SC_OK or SC_MOVED_TEMPORARILY status codes).

If this method is used to set an error code, then the container's error page mechanism will not be triggered. If there is an error and the caller wishes to invoke an error page defined in the web application, then sendError must be used instead.

This method preserves any cookies and other response headers.

Valid status codes are those in the 2XX, 3XX, 4XX, and 5XX ranges. Other status codes are treated as container specific.

Parameters
sc:int

the status code

setStatusback to summary
public void setStatus(int sc, String sm)

Implements javax.servlet.http.HttpServletResponse.setStatus.

Parameters
sc:int

Doc from javax.servlet.http.HttpServletResponse.setStatus.

the status code

sm:String

Doc from javax.servlet.http.HttpServletResponse.setStatus.

the status message

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

org.mortbay.jetty back to summary

private Class Response.NullOutput

extends ServletOutputStream
Class Inheritance

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
print(String
the String to send to the client
s
)

Overrides javax.servlet.ServletOutputStream.print.

Writes a String to the client, without a carriage return-line feed (CRLF) character at the end.
public void
println(String
the String to write to the client
s
)

Overrides javax.servlet.ServletOutputStream.println.

Writes a String to the client, followed by a carriage return-line feed (CRLF).
public void
write(int
the byte.
b
)

Implements abstract java.io.OutputStream.write.

Writes the specified byte to this output stream.
public void
write(byte[]
the data.
b
,
int
the start offset in the data.
off
,
int
the number of bytes to write.
len
)

Overrides java.io.OutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this output stream.
Inherited from javax.servlet.ServletOutputStream:
isReadyprintprintprintprintprintprintprintlnprintlnprintlnprintlnprintlnprintlnprintlnsetWriteListener

Constructor Detail

NullOutputback to summary
private NullOutput()

Method Detail

printback to summary
public void print(String s) throws IOException

Overrides javax.servlet.ServletOutputStream.print.

Doc from javax.servlet.ServletOutputStream.print.

Writes a String to the client, without a carriage return-line feed (CRLF) character at the end.

Parameters
s:String

the String to send to the client

Exceptions
IOException:
if an input or output exception occurred
printlnback to summary
public void println(String s) throws IOException

Overrides javax.servlet.ServletOutputStream.println.

Doc from javax.servlet.ServletOutputStream.println.

Writes a String to the client, followed by a carriage return-line feed (CRLF).

Parameters
s:String

the String to write to the client

Exceptions
IOException:
if an input or output exception occurred
writeback to summary
public void write(int b) throws IOException

Implements abstract java.io.OutputStream.write.

Doc from java.io.OutputStream.write.

Writes the specified byte to this output stream. The general contract for write is that one byte is written to the output stream. The byte to be written is the eight low-order bits of the argument b. The 24 high-order bits of b are ignored.

Parameters
b:int

the byte.

Exceptions
IOException:
if an I/O error occurs. In particular, an IOException may be thrown if the output stream has been closed.
writeback to summary
public void write(byte[] b, int off, int len) throws IOException

Overrides java.io.OutputStream.write.

Doc from java.io.OutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this output stream. The general contract for write(b, off, len) is that some of the bytes in the array b are written to the output stream in order; element b[off] is the first byte written and b[off+len-1] is the last byte written by this operation.

If b is null, a NullPointerException is thrown.

If off is negative, or len is negative, or off+len is greater than the length of the array b, then an IndexOutOfBoundsException is thrown.

Parameters
b:byte[]

the data.

off:int

the start offset in the data.

len:int

the number of bytes to write.

Exceptions
IOException:
if an I/O error occurs. In particular, an IOException is thrown if the output stream is closed.