Skip to content

Instantly share code, notes, and snippets.

@Crydust
Created May 30, 2013 19:01
Show Gist options
  • Save Crydust/5680246 to your computer and use it in GitHub Desktop.
Save Crydust/5680246 to your computer and use it in GitHub Desktop.
CharacterEncodingFilter for java EE 6 (I can't believe I'm writing this AGAIN)
package fileupload;
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;
import javax.servlet.annotation.WebFilter;
@WebFilter(filterName = "CharacterEncodingFilter", urlPatterns = {"/*"})
public class CharacterEncodingFilter implements Filter {
@Override
public void init(FilterConfig filterConfig) throws ServletException {
// NOOP
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
if (request.getCharacterEncoding() == null) {
request.setCharacterEncoding("UTF-8");
}
chain.doFilter(request, response);
}
@Override
public void destroy() {
// NOOP
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment