Top Description Fields Constructors Methods
javax.servlet.http

pack-priv Class NoBodyResponse

Located in compilation unit of javax.servlet.http.HttpServlet.

extends Object
implements HttpServletResponse
Class Inheritance
All Implemented Interfaces
javax.servlet.http.HttpServletResponse, javax.servlet.ServletResponse

A response that includes no body, for use in (dumb) "HEAD" support. This just swallows that body, counting the bytes in order to set the content length appropriately. All other methods delegate directly to the HTTP Servlet Response object used to construct this one.

Field Summary

Modifier and TypeField and Description
private boolean
private NoBodyOutputStream
private HttpServletResponse
private PrintWriter

Constructor Summary

AccessConstructor and Description
pack-priv

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
value
)

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 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 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
encodeRedirectUrl(String
the url to be encoded.
url
)

Implements javax.servlet.http.HttpServletResponse.encodeRedirectUrl.

Deprecated As of Version 2.1, replaced by HttpServletResponse#encodeRedirectURL.
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 in it, or, if encoding is not needed, returns the URL unchanged.
public String
encodeUrl(String
the url to be encoded.
url
)

Implements javax.servlet.http.HttpServletResponse.encodeUrl.

Deprecated As of Version 2.1, replaced by HttpServletResponse#encodeURL.
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 String
getContentType()

Implements javax.servlet.ServletResponse.getContentType.

Returns the content type used for the MIME body sent in this response.
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 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 void
reset()

Implements javax.servlet.ServletResponse.reset.

Clears any data that exists in the buffer as well as the status code and 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
sc
,
String
the descriptive message
msg
)

Implements javax.servlet.http.HttpServletResponse.sendError.

Sends an error response to the client using the specified status.
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 clearing the buffer.
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.
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)
charset
)

Implements javax.servlet.ServletResponse.setCharacterEncoding.

Sets the character encoding (MIME charset) of the response being sent to the client, for example, to UTF-8.
pack-priv void
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
type
)

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
loc
)

Implements javax.servlet.ServletResponse.setLocale.

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

Implements javax.servlet.http.HttpServletResponse.setStatus.

Deprecated
public void
setStatus(int
the status code
sc
)

Implements javax.servlet.http.HttpServletResponse.setStatus.

Sets the status code for this response.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

didSetContentLengthback to summary
private boolean didSetContentLength
noBodyback to summary
private NoBodyOutputStream noBody
respback to summary
private HttpServletResponse resp
writerback to summary
private PrintWriter writer

Constructor Detail

NoBodyResponseback to summary
pack-priv NoBodyResponse(HttpServletResponse r)

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 value)

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

value: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

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

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. Because the rules for making this determination can differ from those used to decide whether to encode a normal link, this method is separete 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.

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.

Deprecated

As of Version 2.1, replaced by 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 in it, 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.

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.

Deprecated

As of Version 2.1, replaced by 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.

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 character encoding may have been specified explicitly using the setCharacterEncoding or setContentType methods, or implicitly using the setLocale 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

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, 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

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.

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.

Returns:ServletOutputStream

a ServletOutputStream for writing binary data

Exceptions
IOException:
if an input or output exception occurred
getWriterback to summary
public PrintWriter getWriter() throws UnsupportedEncodingException

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.

Returns:PrintWriter

a PrintWriter object that can return character data to the client

Exceptions
UnsupportedEncodingException:
if the character encoding returned by getCharacterEncoding cannot be used
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 commited response has already had its status code and headers written.

Returns:boolean

a boolean indicating if the response has been committed

resetback to summary
public void reset() throws IllegalStateException

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 and headers. If the response has been committed, this method throws an IllegalStateException.

Exceptions
IllegalStateException:
if the response has already been committed
resetBufferback to summary
public void resetBuffer() throws IllegalStateException

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 sc, String msg) 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. 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.

Parameters
sc:int

the error status code

msg: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 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.

Parameters
sc:int

the error status code

Exceptions
IOException:
If an input or output exception occurs
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. 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.

Parameters
location:String

the redirect location URL

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

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

Exceptions
IllegalStateException:
if this method is called after content has been written
setCharacterEncodingback to summary
public void setCharacterEncoding(String charset)

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 character encoding has already been set by setContentType or setLocale, this method overrides it. 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
charset:String

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

setContentLengthback to summary
pack-priv void setContentLength()
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 type)

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
type: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 loc)

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
loc:Locale

the locale of the response

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

Implements javax.servlet.http.HttpServletResponse.setStatus.

Deprecated

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

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 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 applicaion, the sendError method should be used instead.

The container clears the buffer and sets the Location header, preserving cookies and other headers.

Parameters
sc:int

the status code