public class CharacterEncodingFilter extends OncePerRequestFilter
This filter can either apply its encoding if the request does not already specify an encoding, or enforce this filter's encoding in any case ("forceEncoding"="true"). In the latter case, the encoding will also be applied as default response encoding (although this will usually be overridden by a full content type set in the view).
setEncoding(java.lang.String)
,
setForceEncoding(boolean)
,
ServletRequest.setCharacterEncoding(java.lang.String)
,
ServletResponse.setCharacterEncoding(java.lang.String)
ALREADY_FILTERED_SUFFIX
logger
Constructor and Description |
---|
CharacterEncodingFilter() |
Modifier and Type | Method and Description |
---|---|
protected void |
doFilterInternal(HttpServletRequest request,
HttpServletResponse response,
FilterChain filterChain)
Same contract as for
doFilter , but guaranteed to be
just invoked once per request within a single request thread. |
void |
setEncoding(String encoding)
Set the encoding to use for requests.
|
void |
setForceEncoding(boolean forceEncoding)
Set whether the configured
encoding of this filter
is supposed to override existing request and response encodings. |
doFilter, getAlreadyFilteredAttributeName, isAsyncDispatch, isAsyncStarted, shouldNotFilter, shouldNotFilterAsyncDispatch, shouldNotFilterErrorDispatch
addRequiredProperty, afterPropertiesSet, destroy, getFilterConfig, getFilterName, getServletContext, init, initBeanWrapper, initFilterBean, setBeanName, setEnvironment, setServletContext
public void setEncoding(String encoding)
ServletRequest.setCharacterEncoding(java.lang.String)
call.
Whether this encoding will override existing request encodings
(and whether it will be applied as default response encoding as well)
depends on the "forceEncoding"
flag.
public void setForceEncoding(boolean forceEncoding)
encoding
of this filter
is supposed to override existing request and response encodings.
Default is "false", i.e. do not modify the encoding if
ServletRequest.getCharacterEncoding()
returns a non-null value. Switch this to "true" to enforce the specified
encoding in any case, applying it as default response encoding as well.
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException
OncePerRequestFilter
doFilter
, but guaranteed to be
just invoked once per request within a single request thread.
See OncePerRequestFilter.shouldNotFilterAsyncDispatch()
for details.
Provides HttpServletRequest and HttpServletResponse arguments instead of the default ServletRequest and ServletResponse ones.
doFilterInternal
in class OncePerRequestFilter
ServletException
IOException