Top Description Fields Constructors Methods
org.apache.catalina.filters

public Class SetCharacterEncodingFilter

extends FilterBase
Class Inheritance
Imports
java.io.IOException, jakarta.servlet.FilterChain, .ServletException, .ServletRequest, .ServletResponse, org.apache.juli.logging.Log, .LogFactory

Example filter that sets the character encoding to be used in parsing the incoming request, either unconditionally or only if the client did not specify a character encoding. Configuration of this filter is based on the following initialization parameters:

Although this filter can be used unchanged, it is also easy to subclass it and make the selectEncoding() method more intelligent about what encoding to choose, based on characteristics of the incoming request (such as the values of the Accept-Language and User-Agent headers, or a value stashed in the current user's session.

Field Summary

Modifier and TypeField and Description
private String
encoding

The default character encoding to set for requests that pass through this filter.

private boolean
ignore

Should a character encoding specified by the client be ignored?

private final Log
Inherited from org.apache.catalina.filters.FilterBase:
sm

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
doFilter(ServletRequest
The servlet request we are processing
request
,
ServletResponse
The servlet response we are creating
response
,
FilterChain
The filter chain we are processing
chain
)

Implements jakarta.servlet.Filter.doFilter.

Select and set (if specified) the character encoding to be used to interpret request parameters for this request.

public String
protected Log
public boolean
protected String

Returns:

the encoding that was configured
selectEncoding
(ServletRequest
The servlet request we are processing
request
)

Select an appropriate character encoding to be used, based on the characteristics of the current request and/or filter initialization parameters.

public void
setEncoding(String encoding)

public void
setIgnore(boolean ignore)

Inherited from org.apache.catalina.filters.FilterBase:
initisConfigProblemFatal

Field Detail

encodingback to summary
private String encoding

The default character encoding to set for requests that pass through this filter.

ignoreback to summary
private boolean ignore

Should a character encoding specified by the client be ignored?

logback to summary
private final Log log

Constructor Detail

SetCharacterEncodingFilterback to summary
public SetCharacterEncodingFilter()

Method Detail

doFilterback to summary
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException

Implements jakarta.servlet.Filter.doFilter.

Select and set (if specified) the character encoding to be used to interpret request parameters for this request.

Parameters
request:ServletRequest

The servlet request we are processing

response:ServletResponse

The servlet response we are creating

chain:FilterChain

The filter chain we are processing

Annotations
@Override
Exceptions
IOException:
if an input/output error occurs
ServletException:
if a servlet error occurs
getEncodingback to summary
public String getEncoding()
getLoggerback to summary
protected Log getLogger()

Implements abstract org.apache.catalina.filters.FilterBase.getLogger.

Annotations
@Override
isIgnoreback to summary
public boolean isIgnore()
selectEncodingback to summary
protected String selectEncoding(ServletRequest request)

Select an appropriate character encoding to be used, based on the characteristics of the current request and/or filter initialization parameters. If no character encoding should be set, return null.

The default implementation unconditionally returns the value configured by the encoding initialization parameter for this filter.

Parameters
request:ServletRequest

The servlet request we are processing

Returns:String

the encoding that was configured

setEncodingback to summary
public void setEncoding(String encoding)
setIgnoreback to summary
public void setIgnore(boolean ignore)