package com.ofrick;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
public class CharacterSetFilter implements Filter {
@Override
public void destroy() {}
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException {
// Respect the client-specified character encoding
// (see HTTP specification section 3.4.1)
if (null == servletRequest.getCharacterEncoding()) {
servletRequest.setCharacterEncoding(„UTF-8“);
}
chain.doFilter(servletRequest, servletResponse);
System.out.println(„response committed? “ + servletResponse.isCommitted());
System.out.println(String.format(„response character-set: %s“, servletResponse.getCharacterEncoding()));
// servletResponse.setCharacterEncoding(„UTF-8“);
}
@Override
public void init(FilterConfig filterConfig) throws ServletException {}
}