Class CharacterEncodingFilter

  extended by org.springframework.web.filter.GenericFilterBean
      extended by org.springframework.web.filter.OncePerRequestFilter
          extended by org.springframework.web.filter.CharacterEncodingFilter
All Implemented Interfaces:
Filter, BeanNameAware, DisposableBean, InitializingBean, ServletContextAware

public class CharacterEncodingFilter
extends OncePerRequestFilter

Servlet 2.3 Filter that allows one to specify a character encoding for requests. This is useful because current browsers typically do not set a character encoding even if specified in the HTML page or form.

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.

Juergen Hoeller
See Also:
setEncoding(java.lang.String), setForceEncoding(boolean)

Field Summary
Fields inherited from class org.springframework.web.filter.OncePerRequestFilter
Fields inherited from class org.springframework.web.filter.GenericFilterBean
Constructor Summary
Method Summary
protected  void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
          Same contract as for doFilter, but guaranteed to be just invoked once per request.
 void setEncoding(String encoding)
          Set the encoding to use for requests.
 void setForceEncoding(boolean forceEncoding)
          Set whether the encoding of this filter should override existing request encodings.
Methods inherited from class org.springframework.web.filter.OncePerRequestFilter
doFilter, getAlreadyFilteredAttributeName, shouldNotFilter
Methods inherited from class org.springframework.web.filter.GenericFilterBean
addRequiredProperty, afterPropertiesSet, destroy, getFilterConfig, getFilterName, getServletContext, init, initBeanWrapper, initFilterBean, setBeanName, setFilterConfig, setServletContext
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail


public CharacterEncodingFilter()
Method Detail


public void setEncoding(String encoding)
Set the encoding to use for requests. This encoding will be passed into a ServletRequest.setCharacterEncoding call.

Whether this encoding will override existing request encodings depends on the "forceEncoding" flag.

See Also:
setForceEncoding(boolean), ServletRequest.setCharacterEncoding(java.lang.String)


public void setForceEncoding(boolean forceEncoding)
Set whether the encoding of this filter should override existing request encodings. Default is "false", i.e. do not modify encoding if ServletRequest.getCharacterEncoding returns a non-null value.

See Also:
setEncoding(java.lang.String), ServletRequest.getCharacterEncoding()


protected void doFilterInternal(HttpServletRequest request,
                                HttpServletResponse response,
                                FilterChain filterChain)
                         throws ServletException,
Description copied from class: OncePerRequestFilter
Same contract as for doFilter, but guaranteed to be just invoked once per request. Provides HttpServletRequest and HttpServletResponse arguments instead of the default ServletRequest and ServletResponse ones.

Specified by:
doFilterInternal in class OncePerRequestFilter

Copyright (c) 2002-2007 The Spring Framework Project.