Top Description Constructors Methods
jakarta.servlet.http

public Class HttpServletResponseWrapper

extends ServletResponseWrapper
implements HttpServletResponse
Class Inheritance
All Implemented Interfaces
jakarta.servlet.http.HttpServletResponse, jakarta.servlet.ServletResponse
Known Direct Subclasses
jakarta.servlet.http.NoBodyResponse
Imports
jakarta.servlet.ServletResponseWrapper, java.io.IOException, java.util.Collection, .Map, java.util.function.Supplier

Provides a convenient implementation of the HttpServletResponse interface that can be subclassed by developers wishing to adapt the response from a Servlet. This class implements the Wrapper or Decorator pattern. Methods default to calling through to the wrapped response object.
Author
Various
Since
Servlet 2.3
See Also
jakarta.servlet.http.HttpServletResponse

Constructor Summary

AccessConstructor and Description
public
HttpServletResponseWrapper(HttpServletResponse
the HttpServletResponse to be wrapped.
response
)

Constructs a response adaptor wrapping the given response.

Method Summary

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

Implements jakarta.servlet.http.HttpServletResponse.addCookie.

The default behavior of this method is to call addCookie(Cookie cookie) on the wrapped response object.

public void
addDateHeader(String
the name of the header to set
name
,
long
the additional date value
date
)

Implements jakarta.servlet.http.HttpServletResponse.addDateHeader.

The default behavior of this method is to call addDateHeader(String name, long date) on the wrapped response object.

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 jakarta.servlet.http.HttpServletResponse.addHeader.

The default behavior of this method is to return addHeader(String name, String value) on the wrapped response object.

public void
addIntHeader(String
the name of the header
name
,
int
the assigned integer value
value
)

Implements jakarta.servlet.http.HttpServletResponse.addIntHeader.

The default behavior of this method is to call addIntHeader(String name, int value) on the wrapped response object.

public boolean
containsHeader(String
the header name
name
)

Implements jakarta.servlet.http.HttpServletResponse.containsHeader.

The default behavior of this method is to call containsHeader(String name) on the wrapped response object.

public String
encodeRedirectURL(String
the url to be encoded.
url
)

Implements jakarta.servlet.http.HttpServletResponse.encodeRedirectURL.

The default behavior of this method is to return encodeRedirectURL(String url) on the wrapped response object.

public String
encodeURL(String
the url to be encoded.
url
)

Implements jakarta.servlet.http.HttpServletResponse.encodeURL.

The default behavior of this method is to call encodeURL(String url) on the wrapped response object.

public String

Returns:

the value of the response header with the given name, or null if no header with the given name has been set on the wrapped response
getHeader
(String
the name of the response header whose value to return
name
)

Implements jakarta.servlet.http.HttpServletResponse.getHeader.

The default behaviour of this method is to call HttpServletResponse#getHeader on the wrapped response object.

public Collection<String>

Returns:

a (possibly empty) Collection of the names of the response headers
getHeaderNames
()

Implements jakarta.servlet.http.HttpServletResponse.getHeaderNames.

The default behaviour of this method is to call HttpServletResponse#getHeaderNames on the wrapped response object.

public Collection<String>

Returns:

a (possibly empty) Collection of the values of the response header with the given name
getHeaders
(String
the name of the response header whose values to return
name
)

Implements jakarta.servlet.http.HttpServletResponse.getHeaders.

The default behaviour of this method is to call HttpServletResponse#getHeaders on the wrapped response object.

public int

Returns:

the current status code of the wrapped response
getStatus
()

Implements jakarta.servlet.http.HttpServletResponse.getStatus.

The default behaviour of this method is to call HttpServletResponse#getStatus on the wrapped response object.

public Supplier<Map<String, String>>

Returns:

supplier of trailer headers
getTrailerFields
()

Overrides default jakarta.servlet.http.HttpServletResponse.getTrailerFields.

The default behaviour of this method is to call HttpServletResponse#getTrailerFields on the wrapped response object.

public void
sendError(int
the error status code
sc
,
String
the descriptive message
msg
)

Implements jakarta.servlet.http.HttpServletResponse.sendError.

The default behavior of this method is to call sendError(int sc, String msg) on the wrapped response object.

public void
sendError(int
the error status code
sc
)

Implements jakarta.servlet.http.HttpServletResponse.sendError.

The default behavior of this method is to call sendError(int sc) on the wrapped response object.

public void
sendRedirect(String
the redirect location URL (may be absolute or relative)
location
)

Overrides default jakarta.servlet.http.HttpServletResponse.sendRedirect.

The default behavior of this method is to return sendRedirect(String location) on the wrapped response object.

public void
sendRedirect(String
the redirect location URL (may be absolute or relative)
location
,
int
the status code to use for the redirect
sc
)

Overrides default jakarta.servlet.http.HttpServletResponse.sendRedirect.

The default behavior of this method is to return sendRedirect(String location, int sc) on the wrapped response object.

public void
sendRedirect(String
the redirect location URL (may be absolute or relative)
location
,
boolean
if true, clear the buffer and replace it with the data set by this method otherwise retain the existing buffer
clearBuffer
)

Overrides default jakarta.servlet.http.HttpServletResponse.sendRedirect.

The default behavior of this method is to return sendRedirect(String location, boolean clearBuffer) on the wrapped response object.

public void
sendRedirect(String
the redirect location URL (may be absolute or relative)
location
,
int
the status code to use for the redirect
sc
,
boolean
if true, clear the buffer and replace it with the data set by this method otherwise retain the existing buffer
clearBuffer
)

Implements jakarta.servlet.http.HttpServletResponse.sendRedirect.

The default behavior of this method is to return sendRedirect(String location, int sc, boolean clearBuffer) on the wrapped response object.

public void
setDateHeader(String
the name of the header to set
name
,
long
the assigned date value
date
)

Implements jakarta.servlet.http.HttpServletResponse.setDateHeader.

The default behavior of this method is to call setDateHeader(String name, long date) on the wrapped response object.

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 jakarta.servlet.http.HttpServletResponse.setHeader.

The default behavior of this method is to return setHeader(String name, String value) on the wrapped response object.

public void
setIntHeader(String
the name of the header
name
,
int
the assigned integer value
value
)

Implements jakarta.servlet.http.HttpServletResponse.setIntHeader.

The default behavior of this method is to call setIntHeader(String name, int value) on the wrapped response object.

public void
setStatus(int
the status code
sc
)

Implements jakarta.servlet.http.HttpServletResponse.setStatus.

The default behavior of this method is to call setStatus(int sc) on the wrapped response object.

public void
setTrailerFields(Supplier<Map<String, String>>
of trailer headers
supplier
)

Overrides default jakarta.servlet.http.HttpServletResponse.setTrailerFields.

The default behaviour of this method is to call HttpServletResponse#setTrailerFields on the wrapped response object.

Inherited from jakarta.servlet.ServletResponseWrapper:
flushBuffergetBufferSizegetCharacterEncodinggetContentTypegetLocalegetOutputStreamgetResponsegetWriterisCommittedisWrapperForisWrapperForresetresetBuffersetBufferSizesetCharacterEncodingsetCharacterEncodingsetContentLengthsetContentLengthLongsetContentTypesetLocalesetResponse

Constructor Detail

HttpServletResponseWrapperback to summary
public HttpServletResponseWrapper(HttpServletResponse response)

Constructs a response adaptor wrapping the given response.

Parameters
response:HttpServletResponse

the HttpServletResponse to be wrapped.

Exceptions
IllegalArgumentException:
if the response is null

Method Detail

_getHttpServletResponseback to summary
private HttpServletResponse _getHttpServletResponse()
addCookieback to summary
public void addCookie(Cookie cookie)

Implements jakarta.servlet.http.HttpServletResponse.addCookie.

The default behavior of this method is to call addCookie(Cookie cookie) on the wrapped response object.

Parameters
cookie:Cookie

Doc from jakarta.servlet.http.HttpServletResponse.addCookie.

the Cookie to return to the client

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

Implements jakarta.servlet.http.HttpServletResponse.addDateHeader.

The default behavior of this method is to call addDateHeader(String name, long date) on the wrapped response object.

Parameters
name:String

Doc from jakarta.servlet.http.HttpServletResponse.addDateHeader.

the name of the header to set

date:long

Doc from jakarta.servlet.http.HttpServletResponse.addDateHeader.

the additional date value

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

Implements jakarta.servlet.http.HttpServletResponse.addHeader.

The default behavior of this method is to return addHeader(String name, String value) on the wrapped response object.

Parameters
name:String

Doc from jakarta.servlet.http.HttpServletResponse.addHeader.

the name of the header

value:String

Doc from jakarta.servlet.http.HttpServletResponse.addHeader.

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

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

Implements jakarta.servlet.http.HttpServletResponse.addIntHeader.

The default behavior of this method is to call addIntHeader(String name, int value) on the wrapped response object.

Parameters
name:String

Doc from jakarta.servlet.http.HttpServletResponse.addIntHeader.

the name of the header

value:int

Doc from jakarta.servlet.http.HttpServletResponse.addIntHeader.

the assigned integer value

Annotations
@Override
containsHeaderback to summary
public boolean containsHeader(String name)

Implements jakarta.servlet.http.HttpServletResponse.containsHeader.

The default behavior of this method is to call containsHeader(String name) on the wrapped response object.

Parameters
name:String

Doc from jakarta.servlet.http.HttpServletResponse.containsHeader.

the header name

Returns:boolean

Doc from jakarta.servlet.http.HttpServletResponse.containsHeader.

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

Annotations
@Override
encodeRedirectURLback to summary
public String encodeRedirectURL(String url)

Implements jakarta.servlet.http.HttpServletResponse.encodeRedirectURL.

The default behavior of this method is to return encodeRedirectURL(String url) on the wrapped response object.

Parameters
url:String

Doc from jakarta.servlet.http.HttpServletResponse.encodeRedirectURL.

the url to be encoded.

Returns:String

Doc from jakarta.servlet.http.HttpServletResponse.encodeRedirectURL.

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

Annotations
@Override
encodeURLback to summary
public String encodeURL(String url)

Implements jakarta.servlet.http.HttpServletResponse.encodeURL.

The default behavior of this method is to call encodeURL(String url) on the wrapped response object.

Parameters
url:String

Doc from jakarta.servlet.http.HttpServletResponse.encodeURL.

the url to be encoded.

Returns:String

Doc from jakarta.servlet.http.HttpServletResponse.encodeURL.

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

Annotations
@Override
getHeaderback to summary
public String getHeader(String name)

Implements jakarta.servlet.http.HttpServletResponse.getHeader.

The default behaviour of this method is to call HttpServletResponse#getHeader on the wrapped response object.

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 the wrapped response

Annotations
@Override
Since
Servlet 3.0
getHeaderNamesback to summary
public Collection<String> getHeaderNames()

Implements jakarta.servlet.http.HttpServletResponse.getHeaderNames.

The default behaviour of this method is to call HttpServletResponse#getHeaderNames on the wrapped response object.

Any changes to the returned Collection must not affect this HttpServletResponseWrapper.

Returns:Collection<String>

a (possibly empty) Collection of the names of the response headers

Annotations
@Override
Since
Servlet 3.0
getHeadersback to summary
public Collection<String> getHeaders(String name)

Implements jakarta.servlet.http.HttpServletResponse.getHeaders.

The default behaviour of this method is to call HttpServletResponse#getHeaders on the wrapped response object.

Any changes to the returned Collection must not affect this HttpServletResponseWrapper.

Parameters
name:String

the name of the response header whose values to return

Returns:Collection<String>

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

Annotations
@Override
Since
Servlet 3.0
getStatusback to summary
public int getStatus()

Implements jakarta.servlet.http.HttpServletResponse.getStatus.

The default behaviour of this method is to call HttpServletResponse#getStatus on the wrapped response object.

Returns:int

the current status code of the wrapped response

Annotations
@Override
Since
Servlet 3.0
getTrailerFieldsback to summary
public Supplier<Map<String, String>> getTrailerFields()

Overrides default jakarta.servlet.http.HttpServletResponse.getTrailerFields.

The default behaviour of this method is to call HttpServletResponse#getTrailerFields on the wrapped response object.

Returns:Supplier<Map<String, String>>

supplier of trailer headers

Annotations
@Override
Since
Servlet 4.0
sendErrorback to summary
public void sendError(int sc, String msg) throws IOException

Implements jakarta.servlet.http.HttpServletResponse.sendError.

The default behavior of this method is to call sendError(int sc, String msg) on the wrapped response object.

Parameters
sc:int

Doc from jakarta.servlet.http.HttpServletResponse.sendError.

the error status code

msg:String

Doc from jakarta.servlet.http.HttpServletResponse.sendError.

the descriptive message

Annotations
@Override
Exceptions
IOException:

Doc from jakarta.servlet.http.HttpServletResponse.sendError.

If an input or output exception occurs

sendErrorback to summary
public void sendError(int sc) throws IOException

Implements jakarta.servlet.http.HttpServletResponse.sendError.

The default behavior of this method is to call sendError(int sc) on the wrapped response object.

Parameters
sc:int

Doc from jakarta.servlet.http.HttpServletResponse.sendError.

the error status code

Annotations
@Override
Exceptions
IOException:

Doc from jakarta.servlet.http.HttpServletResponse.sendError.

If an input or output exception occurs

sendRedirectback to summary
public void sendRedirect(String location) throws IOException

Overrides default jakarta.servlet.http.HttpServletResponse.sendRedirect.

The default behavior of this method is to return sendRedirect(String location) on the wrapped response object.

Parameters
location:String

Doc from jakarta.servlet.http.HttpServletResponse.sendRedirect.

the redirect location URL (may be absolute or relative)

Annotations
@Override
Exceptions
IOException:

Doc from jakarta.servlet.http.HttpServletResponse.sendRedirect.

If an input or output exception occurs

sendRedirectback to summary
public void sendRedirect(String location, int sc) throws IOException

Overrides default jakarta.servlet.http.HttpServletResponse.sendRedirect.

The default behavior of this method is to return sendRedirect(String location, int sc) on the wrapped response object.

Parameters
location:String

Doc from jakarta.servlet.http.HttpServletResponse.sendRedirect.

the redirect location URL (may be absolute or relative)

sc:int

Doc from jakarta.servlet.http.HttpServletResponse.sendRedirect.

the status code to use for the redirect

Annotations
@Override
Exceptions
IOException:

Doc from jakarta.servlet.http.HttpServletResponse.sendRedirect.

If an input or output exception occurs

Since
Servlet 6.1
sendRedirectback to summary
public void sendRedirect(String location, boolean clearBuffer) throws IOException

Overrides default jakarta.servlet.http.HttpServletResponse.sendRedirect.

The default behavior of this method is to return sendRedirect(String location, boolean clearBuffer) on the wrapped response object.

Parameters
location:String

Doc from jakarta.servlet.http.HttpServletResponse.sendRedirect.

the redirect location URL (may be absolute or relative)

clearBuffer:boolean

Doc from jakarta.servlet.http.HttpServletResponse.sendRedirect.

if true, clear the buffer and replace it with the data set by this method otherwise retain the existing buffer

Annotations
@Override
Exceptions
IOException:

Doc from jakarta.servlet.http.HttpServletResponse.sendRedirect.

If an input or output exception occurs

Since
Servlet 6.1
sendRedirectback to summary
public void sendRedirect(String location, int sc, boolean clearBuffer) throws IOException

Implements jakarta.servlet.http.HttpServletResponse.sendRedirect.

The default behavior of this method is to return sendRedirect(String location, int sc, boolean clearBuffer) on the wrapped response object.

Parameters
location:String

Doc from jakarta.servlet.http.HttpServletResponse.sendRedirect.

the redirect location URL (may be absolute or relative)

sc:int

Doc from jakarta.servlet.http.HttpServletResponse.sendRedirect.

the status code to use for the redirect

clearBuffer:boolean

Doc from jakarta.servlet.http.HttpServletResponse.sendRedirect.

if true, clear the buffer and replace it with the data set by this method otherwise retain the existing buffer

Annotations
@Override
Exceptions
IOException:

Doc from jakarta.servlet.http.HttpServletResponse.sendRedirect.

If an input or output exception occurs

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

Implements jakarta.servlet.http.HttpServletResponse.setDateHeader.

The default behavior of this method is to call setDateHeader(String name, long date) on the wrapped response object.

Parameters
name:String

Doc from jakarta.servlet.http.HttpServletResponse.setDateHeader.

the name of the header to set

date:long

Doc from jakarta.servlet.http.HttpServletResponse.setDateHeader.

the assigned date value

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

Implements jakarta.servlet.http.HttpServletResponse.setHeader.

The default behavior of this method is to return setHeader(String name, String value) on the wrapped response object.

Parameters
name:String

Doc from jakarta.servlet.http.HttpServletResponse.setHeader.

the name of the header

value:String

Doc from jakarta.servlet.http.HttpServletResponse.setHeader.

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

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

Implements jakarta.servlet.http.HttpServletResponse.setIntHeader.

The default behavior of this method is to call setIntHeader(String name, int value) on the wrapped response object.

Parameters
name:String

Doc from jakarta.servlet.http.HttpServletResponse.setIntHeader.

the name of the header

value:int

Doc from jakarta.servlet.http.HttpServletResponse.setIntHeader.

the assigned integer value

Annotations
@Override
setStatusback to summary
public void setStatus(int sc)

Implements jakarta.servlet.http.HttpServletResponse.setStatus.

The default behavior of this method is to call setStatus(int sc) on the wrapped response object.

Parameters
sc:int

Doc from jakarta.servlet.http.HttpServletResponse.setStatus.

the status code

Annotations
@Override
setTrailerFieldsback to summary
public void setTrailerFields(Supplier<Map<String, String>> supplier)

Overrides default jakarta.servlet.http.HttpServletResponse.setTrailerFields.

The default behaviour of this method is to call HttpServletResponse#setTrailerFields on the wrapped response object.

Parameters
supplier:Supplier<Map<String, String>>

of trailer headers

Annotations
@Override
Since
Servlet 4.0