public class ServletResponse extends H.Response<ServletResponse>
outputStream, writer| Constructor and Description |
|---|
ServletResponse(javax.servlet.http.HttpServletResponse resp) |
| Modifier and Type | Method and Description |
|---|---|
protected Class<ServletResponse> |
_impl()
Returns the class of the implementation.
|
protected void |
_setContentType(String type)
Sub class to overwrite this method to set content type to
the response
|
protected void |
_setLocale(Locale loc)
Sets the locale of the response, setting the headers (including the
Content-Type's charset) as appropriate.
|
void |
addCookie(H.Cookie cookie)
Adds the specified cookie to the response.
|
ServletResponse |
addHeader(String name,
String value)
Adds a response header with the given name and value.
|
String |
characterEncoding()
Returns the name of the character encoding (MIME charset)
used for the body sent in this response.
|
ServletResponse |
characterEncoding(String encoding)
Returns the content type used for the MIME body
sent in this response.
|
void |
commit()
Calling this method commits the response, meaning the status
code and headers will be written to the client
|
boolean |
containsHeader(String name)
Returns a boolean indicating whether the named response header
has already been set.
|
ServletResponse |
contentLength(long len)
Set the length of the content to be write to the response
|
protected OutputStream |
createOutputStream() |
ServletResponse |
header(String name,
String value)
Sets a response header with the given name and value.
|
Locale |
locale()
Returns the locale assigned to the response.
|
ServletResponse |
sendError(int sc)
Sends an error response to the client using the specified status
code and clearing the buffer.
|
ServletResponse |
sendError(int sc,
String msg)
Sends an error response to the client using the specified
status.
|
ServletResponse |
sendRedirect(String location)
Sends a temporary redirect response to the client using the
specified redirect location URL.
|
ServletResponse |
status(int sc)
Sets the status code for this response.
|
ServletResponse |
writeContent(ByteBuffer buffer)
This method is not supported in ServletResponse
|
addHeaderIfNotAdded, contentDisposition, contentType, context, context, current, current, etag, initContentType, locale, me, outputStream, prepareDownload, printWriter, sendError, status, writeBinary, writeContent, writeHtml, writeJSON, writer, writerCreated, writeTextpublic ServletResponse(javax.servlet.http.HttpServletResponse resp)
protected Class<ServletResponse> _impl()
H.Response_impl in class H.Response<ServletResponse>public String characterEncoding()
H.ResponseH.Response.characterEncoding(String) or
H.Response.contentType(String) methods, or implicitly using the
H.Response.locale(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.
characterEncoding in class H.Response<ServletResponse>String specifying the
name of the character encoding, for
example, UTF-8public ServletResponse characterEncoding(String encoding)
H.ResponseH.Response.contentType(String)
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 H.Response.characterEncoding()
or H.Response.writer() has been called,
the charset parameter is included in the string returned.
If no character encoding has been specified, the
charset parameter is omitted.characterEncoding in class H.Response<ServletResponse>encoding - the encodingString specifying the
content type, for example,
text/html; charset=UTF-8,
or nullpublic ServletResponse contentLength(long len)
H.ResponsecontentLength in class H.Response<ServletResponse>len - an long value specifying the length of the
content being returned to the client; sets
the Content-Length headerH.Response.outputStream,
H.Response.writerpublic ServletResponse writeContent(ByteBuffer buffer)
writeContent in class H.Response<ServletResponse>buffer - direct byte bufferprotected OutputStream createOutputStream()
createOutputStream in class H.Response<ServletResponse>protected void _setContentType(String type)
H.Response_setContentType in class H.Response<ServletResponse>type - a String specifying the MIME
type of the contentprotected void _setLocale(Locale loc)
H.ResponseH.Response.writer(). By default, the response locale
is the default locale for the server._setLocale in class H.Response<ServletResponse>loc - the locale of the responseH.Response.locale()public Locale locale()
H.Responselocale in class H.Response<ServletResponse>H.Response.locale(java.util.Locale)public void addCookie(H.Cookie cookie)
H.ResponseaddCookie in class H.Response<ServletResponse>cookie - the Cookie to return to the clientpublic boolean containsHeader(String name)
H.ResponsecontainsHeader in class H.Response<ServletResponse>name - the header nametrue if the named response header
has already been set;
false otherwisepublic ServletResponse sendError(int sc, String msg)
H.ResponseIf 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 class H.Response<ServletResponse>sc - the error status codemsg - the descriptive messagepublic ServletResponse sendError(int sc)
H.ResponseIf 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 class H.Response<ServletResponse>sc - the error status codepublic ServletResponse sendRedirect(String location)
H.ResponseIf 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 class H.Response<ServletResponse>location - the redirect location URLpublic ServletResponse header(String name, String value)
H.ResponsecontainsHeader method can be
used to test for the presence of a header before setting its
value.header in class H.Response<ServletResponse>name - the name of the headervalue - the header value If it contains octet string,
it should be encoded according to RFC 2047
(http://www.ietf.org/rfc/rfc2047.txt)H.Response.containsHeader(java.lang.String),
H.Response.addHeader(java.lang.String, java.lang.String)public ServletResponse status(int sc)
H.ResponsesendError method should be used
instead.
The container clears the buffer and sets the Location header, preserving cookies and other headers.
status in class H.Response<ServletResponse>sc - the status codeH.Response.sendError(int, java.lang.String),
H.Response.status(int)public ServletResponse addHeader(String name, String value)
H.ResponseaddHeader in class H.Response<ServletResponse>name - the name of the headervalue - the additional header value If it contains
octet string, it should be encoded
according to RFC 2047
(http://www.ietf.org/rfc/rfc2047.txt)H.Response.header(String, String)public void commit()
H.Responsecommit in class H.Response<ServletResponse>Copyright © 2017. All Rights Reserved.