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(); } public interface FilterChain { public void doFilter ( ServletRequest request, ServletResponse response ) throws IOException, ServletException; } public class MyFilter1 implements Filter { public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { System.out.println("do something in filter1"); chain.doFilter(request, response); } public void init(FilterConfig fc) throws ServletException { } public void destroy() { } } public class MyFilter2 implements Filter { public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { System.out.println("do something in filter2"); chain.doFilter(request, response); } public void init(FilterConfig fc) throws ServletException { } public void destroy() { } } private class MyChain implements FilterChain { private FilterInvocation fi; private Filter[] allFilters; private int currentPosition = 0; public MyChain(Filter[] allFilters) { this.allFilters = allFilters; } public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException { if (currentPosition == allFilters.length) { ...... System.out.println("all filters finished their job"); } else { currentPosition++; ...... allFilters[currentPosition - 1].doFilter(request, response, this); } } } MyFilter1 filter1 = new MyFilter1(); MyFilter2 filter2 = new MyFilter2(); MyChain myChain = new MyChain(new Filter[]{filter1,filter2}); myChain.doFilter(request,response);