I wrote a filter that needs to be invoked every time a url on my site is accessed EXCEPT the CSS, JS, and IMAGE files. So in my definition I\'d like to have something like
I think you can try this one:
@WebFilter(filterName = "myFilter", urlPatterns = {"*.xhtml"})
public class MyFilter implements Filter {
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
String path = ((HttpServletRequest) request).getServletPath();
if (excludeFromFilter(path)) chain.doFilter(request, response);
else // do something
}
private boolean excludeFromFilter(String path) {
if (path.startsWith("/javax.faces.resource")) return true; // add more page to exclude here
else return false;
}
}