Use a CharacterEncodingFilter (like this one, taken from Spring) to force UTF-8 as the encoding of all requests and responses:
public class CharacterEncodingFilter implements Filter {
private String encoding;
private boolean forceEncoding;
@Override
public final void init(FilterConfig filterConfig) throws ServletException {
String encod = filterConfig.getInitParameter("encoding");
if(encod !=null){
encoding = encod ;
}
String forceEncod = filterConfig.getInitParameter("forceEncoding");
if(forceEncod !=null){
forceEncoding = forceEncod ;
}
}
public final void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws ServletException, IOException {
if (this.encoding != null && (this.forceEncoding || request.getCharacterEncoding() == null)) {
request.setCharacterEncoding(this.encoding);
if (this.forceEncoding) {
response.setCharacterEncoding(this.encoding);
}
}
filterChain.doFilter(request, response);
}
}
web.xml
<!-- Enforce UTF-8 Character Encoding -->
<filter>
<filter-name>charEncodingFilter</filter-name>
<filter-class>somepackages.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>