public interface Filter { public void init(FilterConfig filterConfig) throws ServletException; public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException; public void destroy(); }
The filter is mapped to an url pattern. The doFilter method of the filter is called by the container each time a resource is accessed withing that url pattern. doFilter() implementation can call FilterChain#doFilter method for the requested resource, or it might block it by not calling the method. destroy() and init() methods are life cycle methods for initialization and cleaning up the resources respectively.
Implementing the Filter interface to log request and response headers.