Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
package br.com.foo.web.filters;
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.http.HttpServletRequest;
public class EncodingFilter implements Filter {
public void doFilter(ServletRequest req, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;
response.setCharacterEncoding("UTF-8");
request.setCharacterEncoding("UTF-8");
if(request.getRequestURI().endsWith(".js")) {
response.setContentType("text/application/x-javascript; charset=UTF-8");
}
filterChain.doFilter(request, response);
}
public void init(FilterConfig arg0) throws ServletException {
}
public void destroy() {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment