
Originally Posted by
davison
It strikes me that it's possibly a fault of the servlet container - which one are you using?
Resin 3.0.7 - I wonder if the others are smarter about this?
Carl-Eric, thanks for your suggestions. The filter works and seems cleaner than messing with isFormSubmission. For anybody else running into the same problem, here's a sample filter, with set-up in web.xml and code.
Code:
<filter>
<filter-name>
charsetFilter
</filter-name>
<filter-class>
com.blah.blah.blah.CharsetFilter
</filter-class>
<init-param>
<param-name>requestEncoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>charsetFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Code:
public class CharsetFilter implements Filter {
FilterConfig config;
String encoding = "UTF-8";
/**
* @see javax.servlet.Filter#destroy()
*/
public void destroy() {
}
/**
* Sets the character encoding on the request
* @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
*/
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
request.setCharacterEncoding(encoding);
chain.doFilter(request, response);
}
/**
* @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
*/
public void init(FilterConfig config) throws ServletException {
this.config = config;
this.encoding = config.getInitParameter("requestEncoding");
}
}
Regarding accept-charset: I presume this is supposed to indicate to the Browser that it should automatically reject any input not matching a particular charset (?). I don't find the definition in the w3c recommendations very clear. Anyway, it's completely ignored by Firefox 0.8, tested by entering Russian characters on ISO-8859-1 which all got sent correctly. So for now, using "accept-charset" seems like needless typing...