|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--org.mortbay.jetty.servlet.ServletHttpResponse
Servlet Response Wrapper. This class wraps a Jetty HTTP response as a 2.2 Servlet response. Note that this wrapper is not synchronized and if a response is to be operated on by multiple threads, then higher level synchronizations may be required.
| Field Summary | |
static int |
DISABLED
|
static int |
NO_OUT
|
static int |
OUTPUTSTREAM_OUT
|
static int |
WRITER_OUT
|
| Method Summary | |
void |
addCookie(Cookie cookie)
Adds the specified cookie to the response. |
void |
addDateHeader(java.lang.String name,
long value)
Adds a response header with the given name and date-value. |
void |
addHeader(java.lang.String name,
java.lang.String value)
Adds a response header with the given name and value. |
void |
addIntHeader(java.lang.String name,
int value)
Adds a response header with the given name and integer value. |
boolean |
containsHeader(java.lang.String name)
Returns a boolean indicating whether the named response header has already been set. |
java.lang.String |
encodeRedirectUrl(java.lang.String url)
Deprecated. As of version 2.1, use encodeRedirectURL(String url) instead |
java.lang.String |
encodeRedirectURL(java.lang.String url)
Encodes the specified URL for use in the sendRedirect method or, if encoding is not needed,
returns the URL unchanged. |
java.lang.String |
encodeUrl(java.lang.String url)
Deprecated. As of version 2.1, use encodeURL(String url) instead |
java.lang.String |
encodeURL(java.lang.String url)
Encodes the specified URL by including the session ID in it, or, if encoding is not needed, returns the URL unchanged. |
void |
flushBuffer()
Forces any content in the buffer to be written to the client. |
int |
getBufferSize()
Returns the actual buffer size used for the response. |
java.lang.String |
getCharacterEncoding()
Returns the name of the charset used for the MIME body sent in this response. |
java.util.Locale |
getLocale()
Returns the locale assigned to the response. |
ServletOutputStream |
getOutputStream()
Returns a ServletOutputStream suitable for writing binary
data in the response. |
java.io.PrintWriter |
getWriter()
Returns a PrintWriter object that
can send character text to the client. |
boolean |
isCommitted()
Returns a boolean indicating if the response has been committed. |
void |
reset()
Clears any data that exists in the buffer as well as the status code and headers. |
void |
resetBuffer()
Clears the content of the underlying buffer in the response without clearing headers or status code. |
void |
sendError(int status)
Sends an error response to the client using the specified status code and clearing the buffer. |
void |
sendError(int status,
java.lang.String message)
Sends an error response to the client using the specified status clearing the buffer. |
void |
sendRedirect(java.lang.String url)
Sends a temporary redirect response to the client using the specified redirect location URL. |
void |
setBufferSize(int size)
Sets the preferred buffer size for the body of the response. |
void |
setContentLength(int len)
Sets the length of the content body in the response In HTTP servlets, this method sets the HTTP Content-Length header. |
void |
setContentType(java.lang.String contentType)
Sets the content type of the response being sent to the client. |
void |
setDateHeader(java.lang.String name,
long value)
Sets a response header with the given name and date-value. |
void |
setHeader(java.lang.String name,
java.lang.String value)
Sets a response header with the given name and value. |
void |
setIntHeader(java.lang.String name,
int value)
Sets a response header with the given name and integer value. |
void |
setLocale(java.util.Locale locale)
Sets the locale of the response, setting the headers (including the Content-Type's charset) as appropriate. |
void |
setStatus(int status)
Sets the status code for this response. |
void |
setStatus(int status,
java.lang.String message)
Deprecated. As of version 2.1 of the Servlet spec. To set a status code use setStatus(int), to send an error with a description
use sendError(int, String).
Sets the status code and message for this response. |
java.lang.String |
toString()
|
static ServletHttpResponse |
unwrap(ServletResponse response)
Unwrap a ServletResponse. |
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
public static final int DISABLED
public static final int NO_OUT
public static final int OUTPUTSTREAM_OUT
public static final int WRITER_OUT
| Method Detail |
public boolean isCommitted()
ServletResponse
isCommitted in interface ServletResponseServletResponse.setBufferSize(int),
ServletResponse.getBufferSize(),
ServletResponse.flushBuffer(),
ServletResponse.reset()public void setBufferSize(int size)
ServletResponsegetBufferSize.
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, this method throws an
IllegalStateException.
setBufferSize in interface ServletResponsesize - the preferred buffer sizeServletResponse.getBufferSize(),
ServletResponse.flushBuffer(),
ServletResponse.isCommitted(),
ServletResponse.reset()public int getBufferSize()
ServletResponse
getBufferSize in interface ServletResponseServletResponse.setBufferSize(int),
ServletResponse.flushBuffer(),
ServletResponse.isCommitted(),
ServletResponse.reset()
public void flushBuffer()
throws java.io.IOException
ServletResponse
flushBuffer in interface ServletResponsejava.io.IOExceptionServletResponse.setBufferSize(int),
ServletResponse.getBufferSize(),
ServletResponse.isCommitted(),
ServletResponse.reset()public void resetBuffer()
ServletResponseIllegalStateException.
resetBuffer in interface ServletResponseServletResponse.setBufferSize(int),
ServletResponse.getBufferSize(),
ServletResponse.isCommitted(),
ServletResponse.reset()public void reset()
ServletResponseIllegalStateException.
reset in interface ServletResponseServletResponse.setBufferSize(int),
ServletResponse.getBufferSize(),
ServletResponse.flushBuffer(),
ServletResponse.isCommitted()public void setLocale(java.util.Locale locale)
getWriter(). By default, the response locale
is the default locale for the server.
setLocale in interface ServletResponselocale - the Locale of the responsegetLocale()public java.util.Locale getLocale()
ServletResponse
getLocale in interface ServletResponseServletResponse.setLocale(java.util.Locale)public void addCookie(Cookie cookie)
HttpServletResponse
addCookie in interface HttpServletResponsecookie - the Cookie to return to the clientpublic boolean containsHeader(java.lang.String name)
HttpServletResponse
containsHeader in interface HttpServletResponsename - the header name
true if the named response header
has already been set;
false otherwisepublic java.lang.String encodeURL(java.lang.String url)
HttpServletResponseFor 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.
encodeURL in interface HttpServletResponseurl - the url to be encoded.
public java.lang.String encodeRedirectURL(java.lang.String url)
HttpServletResponsesendRedirect 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. Because the rules for making
this determination can differ from those used to decide whether to
encode a normal link, this method is seperate 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.
encodeRedirectURL in interface HttpServletResponseurl - the url to be encoded.
HttpServletResponse.sendRedirect(java.lang.String),
HttpServletResponse.encodeUrl(java.lang.String)public java.lang.String encodeUrl(java.lang.String url)
encodeUrl in interface HttpServletResponseurl - the url to be encoded.
public java.lang.String encodeRedirectUrl(java.lang.String url)
encodeRedirectUrl in interface HttpServletResponseurl - the url to be encoded.
public void sendError(int status,
java.lang.String message)
throws java.io.IOException
HttpServletResponseIf 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.
sendError in interface HttpServletResponsestatus - the error status codemessage - the descriptive message
java.io.IOException - If an input or output exception occurs
public void sendError(int status)
throws java.io.IOException
HttpServletResponseIf 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.
sendError in interface HttpServletResponsestatus - the error status code
java.io.IOException - If an input or output exception occurs
public void sendRedirect(java.lang.String url)
throws java.io.IOException
HttpServletResponseIf 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.
sendRedirect in interface HttpServletResponseurl - the redirect location URL
java.io.IOException - If an input or output exception occurs
public void setDateHeader(java.lang.String name,
long value)
HttpServletResponsecontainsHeader method can be used to test for the
presence of a header before setting its value.
setDateHeader in interface HttpServletResponsename - the name of the header to setHttpServletResponse.containsHeader(java.lang.String),
HttpServletResponse.addDateHeader(java.lang.String, long)
public void setHeader(java.lang.String name,
java.lang.String value)
HttpServletResponsecontainsHeader method can be
used to test for the presence of a header before setting its
value.
setHeader in interface HttpServletResponsename - the name of the headervalue - the header valueHttpServletResponse.containsHeader(java.lang.String),
HttpServletResponse.addHeader(java.lang.String, java.lang.String)
public void setIntHeader(java.lang.String name,
int value)
HttpServletResponsecontainsHeader
method can be used to test for the presence of a header before
setting its value.
setIntHeader in interface HttpServletResponsename - the name of the headervalue - the assigned integer valueHttpServletResponse.containsHeader(java.lang.String),
HttpServletResponse.addIntHeader(java.lang.String, int)
public void addDateHeader(java.lang.String name,
long value)
HttpServletResponse
addDateHeader in interface HttpServletResponsename - the name of the header to setHttpServletResponse.setDateHeader(java.lang.String, long)
public void addHeader(java.lang.String name,
java.lang.String value)
HttpServletResponse
addHeader in interface HttpServletResponsename - the name of the headervalue - the additional header valueHttpServletResponse.setHeader(java.lang.String, java.lang.String)
public void addIntHeader(java.lang.String name,
int value)
HttpServletResponse
addIntHeader in interface HttpServletResponsename - the name of the headervalue - the assigned integer valueHttpServletResponse.setIntHeader(java.lang.String, int)public void setStatus(int status)
HttpServletResponsesendError method should be used
instead.
The container clears the buffer and sets the Location header, preserving cookies and other headers.
setStatus in interface HttpServletResponsestatus - the status codeHttpServletResponse.sendError(int, java.lang.String)
public void setStatus(int status,
java.lang.String message)
setStatus(int), to send an error with a description
use sendError(int, String).
Sets the status code and message for this response.
setStatus in interface HttpServletResponsestatus - the status codemessage - the status messagepublic java.lang.String getCharacterEncoding()
ServletResponseIf no charset has been assigned, it is implicitly
set to ISO-8859-1 (Latin-1).
See RFC 2047 (http://ds.internic.net/rfc/rfc2045.txt) for more information about character encoding and MIME.
getCharacterEncoding in interface ServletResponseString specifying the
name of the charset, for
example, ISO-8859-1public ServletOutputStream getOutputStream()
ServletResponseServletOutputStream 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 ServletResponse.getWriter() may
be called to write the body, not both.
getOutputStream in interface ServletResponseServletOutputStream for writing binary dataServletResponse.getWriter()
public java.io.PrintWriter getWriter()
throws java.io.IOException
ServletResponsePrintWriter object that
can send character text to the client.
The character encoding used is the one specified
in the charset= property of the
ServletResponse.setContentType(java.lang.String) method, which must be called
before calling this method for the charset to take effect.
If necessary, the MIME type of the response is modified to reflect the character encoding used.
Calling flush() on the PrintWriter commits the response.
Either this method or ServletResponse.getOutputStream() may be called
to write the body, not both.
getWriter in interface ServletResponsePrintWriter object that
can return character data to the client
java.io.IOException - if an input or output exception occurredServletResponse.getOutputStream(),
ServletResponse.setContentType(java.lang.String)public void setContentLength(int len)
ServletResponse
setContentLength in interface ServletResponselen - an integer specifying the length of the
content being returned to the client; sets
the Content-Length headerpublic void setContentType(java.lang.String contentType)
ServletResponsetext/html; charset=ISO-8859-4.
If obtaining a PrintWriter, this method should be
called first.
setContentType in interface ServletResponsecontentType - a String specifying the MIME
type of the contentServletResponse.getOutputStream(),
ServletResponse.getWriter()public java.lang.String toString()
toString in class java.lang.Objectpublic static ServletHttpResponse unwrap(ServletResponse response)
response -
ServletResponseWrapper,
HttpServletResponseWrapper
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||