org.apache.catalina.filters
Class SetCharacterEncodingFilter

java.lang.Object
  extended byorg.apache.catalina.filters.SetCharacterEncodingFilter
All Implemented Interfaces:
javax.servlet.Filter

public class SetCharacterEncodingFilter
extends java.lang.Object
implements javax.servlet.Filter

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
protected static StringManager sm
           
 
Constructor Summary
SetCharacterEncodingFilter()
           
 
Method Summary
 void destroy()
           
 void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain)
          Select and set (if specified) the character encoding to be used to interpret request parameters for this request.
 java.lang.String getEncoding()
           
 void init(javax.servlet.FilterConfig filterConfig)
           
 boolean isIgnore()
           
protected  java.lang.String selectEncoding(javax.servlet.ServletRequest request)
          Select an appropriate character encoding to be used, based on the characteristics of the current request and/or filter initialization parameters.
 void setEncoding(java.lang.String encoding)
           
 void setIgnore(boolean ignore)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sm

protected static final StringManager sm
Constructor Detail

SetCharacterEncodingFilter

public SetCharacterEncodingFilter()
Method Detail

setEncoding

public void setEncoding(java.lang.String encoding)

getEncoding

public java.lang.String getEncoding()

setIgnore

public void setIgnore(boolean ignore)

isIgnore

public boolean isIgnore()

init

public void init(javax.servlet.FilterConfig filterConfig)
          throws javax.servlet.ServletException
Specified by:
init in interface javax.servlet.Filter
Throws:
javax.servlet.ServletException

destroy

public void destroy()
Specified by:
destroy in interface javax.servlet.Filter

doFilter

public void doFilter(javax.servlet.ServletRequest request,
                     javax.servlet.ServletResponse response,
                     javax.servlet.FilterChain chain)
              throws java.io.IOException,
                     javax.servlet.ServletException
Select and set (if specified) the character encoding to be used to interpret request parameters for this request.

Specified by:
doFilter in interface javax.servlet.Filter
Parameters:
request - The servlet request we are processing
response - The servlet response we are creating
chain - The filter chain we are processing
Throws:
java.io.IOException - if an input/output error occurs
javax.servlet.ServletException - if a servlet error occurs

selectEncoding

protected java.lang.String selectEncoding(javax.servlet.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 - The servlet request we are processing


Copyright © 2000-2012 Apache Software Foundation. All Rights Reserved.