org.mmbase.servlet
Class CharacterEncodingFilter

java.lang.Object
  extended by org.mmbase.servlet.CharacterEncodingFilter
All Implemented Interfaces:
Filter

public class CharacterEncodingFilter
extends Object
implements Filter

There's large simularity in the way data travels from and to a web server. But unfortunately there is one difference: while the web server tells the browser what character encoding the page it sends is in (via the Content-Type HTTP header), the client does not send such information. Accordingly to the HTTP spec the HTTP request the browser send to the server (that contains the submitted form) may well contain the Content-Type header too. This would give the server the key to decript the form parameters. Regretfully our present internet browsers do not send it The browser generally does the following: it takes user input in national characters

Then the encoded query (possibly containing %xy codes) is sent to the server. ascii characters, according to the procedure described above are sent to the server as they are, provided that they have the same codes both in ascii character encoding and in the national character encoding that is used. This filter sets the character encoding before parameters are handled. The filter sets the character encoding by the following information: Get it to work by incorporating the following piece of XML in your web.xml:

  <filter>
    <filter-name>Set Character Encoding</filter-name>
    <filter-class>org.mmbase.servlet.CharacterEncodingFilter</filter-class>
    <!-- Overrides config/module/mmbaseroot.xml#encoding -->
    <!-- <init-param>
      <param-name>encoding</param-name>
      <param-value>UTF-8</param-value>
    </init-param>
    -->
  </filter>

  <filter-mapping>
    <filter-name>Set Character Encoding</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
 

Since:
MMBase-1.6
Version:
$Id: CharacterEncodingFilter.java 34900 2009-05-01 16:29:42Z michiel $
Author:
P.S.D.Reitsma (Finalist IT Group), Nico Klasens (Finalist IT Group)

Constructor Summary
CharacterEncodingFilter()
           
 
Method Summary
 void destroy()
           
 void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
           
 void init(FilterConfig config)
           
 
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

init

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

destroy

public void destroy()
Specified by:
destroy in interface Filter
See Also:
Filter.destroy()

doFilter

public void doFilter(ServletRequest request,
                     ServletResponse response,
                     FilterChain chain)
              throws IOException,
                     ServletException
Specified by:
doFilter in interface Filter
Throws:
IOException
ServletException
See Also:
Filter.doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)


MMBase 2.0-SNAPSHOT - null