public class ServletResponse extends H.Response<ServletResponse>
output, 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 org.osgl.util.Output |
createOutput() |
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.
|
int |
statusCode()
Get the status code of this response.
|
ServletResponse |
writeContent(ByteBuffer buffer)
This method is not supported in ServletResponse
|
addHeaderIfNotAdded, close, contentDisposition, contentType, context, context, current, current, etag, initContentType, locale, me, output, outputCreated, outputStream, outputStreamCreated, prepareDownload, printWriter, sendError, status, writeBinary, writeContent, writeHtml, writeJSON, writer, writerCreated, writeTextpublic ServletResponse(javax.servlet.http.HttpServletResponse resp)
protected Class<ServletResponse> _impl()
H.ResponseReturns the class of the implementation. Not to be used by application
_impl in class H.Response<ServletResponse>public String characterEncoding()
H.ResponseReturns the name of the character encoding (MIME charset) used for the body sent in this response. The character encoding may have been specified explicitly using the H.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.ResponseReturns the content type used for the MIME body sent in this response. The content type proper must have been specified using H.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.ResponseSet the length of the content to be write to the response
contentLength 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)
This method is not supported in ServletResponse
writeContent in class H.Response<ServletResponse>buffer - direct byte bufferprotected OutputStream createOutputStream()
createOutputStream in class H.Response<ServletResponse>protected org.osgl.util.Output createOutput()
createOutput in class H.Response<ServletResponse>protected void _setContentType(String type)
H.ResponseSub class to overwrite this method to set content type to the response
_setContentType in class H.Response<ServletResponse>type - a String specifying the MIME type of the contentprotected void _setLocale(Locale loc)
H.ResponseSets the locale of the response, setting the headers (including the Content-Type’s charset) as appropriate. This method should be called before a call to H.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.ResponseReturns the locale assigned to the response.
locale in class H.Response<ServletResponse>H.Response.locale(java.util.Locale)public void addCookie(H.Cookie cookie)
H.ResponseAdds the specified cookie to the response. This method can be called multiple times to add more than one cookie.
addCookie in class H.Response<ServletResponse>cookie - the Cookie to return to the clientpublic boolean containsHeader(String name)
H.ResponseReturns a boolean indicating whether the named response header has already been set.
containsHeader 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.ResponseSends an error response to the client using the specified status. 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”, leaving cookies and other headers unmodified.
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.
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.
sendError in class H.Response<ServletResponse>sc - the error status codemsg - the descriptive messagepublic ServletResponse sendError(int sc)
H.ResponseSends an error response to the client using the specified status code and clearing the buffer.
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.
sendError in class H.Response<ServletResponse>sc - the error status codepublic ServletResponse sendRedirect(String location)
H.ResponseSends a temporary redirect response to the client using the specified redirect location URL. 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 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.ResponseSets 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.
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.ResponseSets 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 status codes SC_OK or SC_MOVED_TEMPORARILY). If there is an error, and the caller wishes to invoke an error-page defined in the web application, the sendError 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 int statusCode()
H.ResponseGet the status code of this response.
If the status code has not been set to this response, -1 should be returned.
statusCode in class H.Response<ServletResponse>public ServletResponse addHeader(String name, String value)
H.ResponseAdds a response header with the given name and value. This method allows response headers to have multiple values.
addHeader 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.ResponseCalling this method commits the response, meaning the status code and headers will be written to the client
commit in class H.Response<ServletResponse>Copyright © 2017–2018 OSGL (Open Source General Library). All rights reserved.