public class

CharacterEncodingFilter

extends OncePerRequestFilter
java.lang.Object
   ↳ org.springframework.web.filter.GenericFilterBean
     ↳ org.springframework.web.filter.OncePerRequestFilter
       ↳ org.springframework.web.filter.CharacterEncodingFilter

Class Overview

Servlet 2.3/2.4 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 ("forceEncoding"="true"). In the latter case, the encoding will also be applied as default response encoding on Servlet 2.4+ containers (although this will usually be overridden by a full content type set in the view).

Summary

[Expand]
Inherited Constants
From class org.springframework.web.filter.OncePerRequestFilter
[Expand]
Inherited Fields
From class org.springframework.web.filter.GenericFilterBean
Public Constructors
CharacterEncodingFilter()
Public Methods
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.
Protected Methods
void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
Same contract as for doFilter, but guaranteed to be just invoked once per request.
[Expand]
Inherited Methods
From class org.springframework.web.filter.OncePerRequestFilter
From class org.springframework.web.filter.GenericFilterBean
From class java.lang.Object
From interface javax.servlet.Filter
From interface org.springframework.beans.factory.BeanNameAware
From interface org.springframework.beans.factory.DisposableBean
From interface org.springframework.beans.factory.InitializingBean
From interface org.springframework.context.EnvironmentAware
From interface org.springframework.web.context.ServletContextAware

Public Constructors

public CharacterEncodingFilter ()

Public Methods

public void setEncoding (String encoding)

Set the encoding to use for requests. This encoding will be passed into a setCharacterEncoding(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)

Set whether the configured encoding of this filter is supposed to override existing request and response encodings.

Default is "false", i.e. do not modify the encoding if 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.

Note that the response encoding will only be set on Servlet 2.4+ containers, since Servlet 2.3 did not provide a facility for setting a default response encoding.

Protected Methods

protected void doFilterInternal (HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)

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.

Throws
IOException
ServletException