Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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;
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