org.springframework.web.filter
Class CharacterEncodingFilter

java.lang.Object
  extended byorg.springframework.web.filter.GenericFilterBean
      extended byorg.springframework.web.filter.OncePerRequestFilter
          extended byorg.springframework.web.filter.CharacterEncodingFilter
All Implemented Interfaces:
javax.servlet.Filter

public class CharacterEncodingFilter
extends OncePerRequestFilter

Servlet 2.3 Filter that allows 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 respectively form.

Can either just apply this filter's encoding if the request does not already specify an encoding, or apply this filter's encoding in any case.

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

Field Summary
 
Fields inherited from class org.springframework.web.filter.OncePerRequestFilter
ALREADY_FILTERED_SUFFIX
 
Fields inherited from class org.springframework.web.filter.GenericFilterBean
logger
 
Constructor Summary
CharacterEncodingFilter()
           
 
Method Summary
protected  void doFilterInternal(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.FilterChain filterChain)
          Same contract as for doFilter, but guaranteed to be just invoked once per request.
 void setEncoding(java.lang.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, destroy, getFilterConfig, getFilterName, getServletContext, init, initFilterBean
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CharacterEncodingFilter

public CharacterEncodingFilter()
Method Detail

setEncoding

public void setEncoding(java.lang.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)

setForceEncoding

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

doFilterInternal

protected void doFilterInternal(javax.servlet.http.HttpServletRequest request,
                                javax.servlet.http.HttpServletResponse response,
                                javax.servlet.FilterChain filterChain)
                         throws javax.servlet.ServletException,
                                java.io.IOException
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
Throws:
javax.servlet.ServletException
java.io.IOException


Copyright (C) 2003-2004 The Spring Framework Project.