1 2 package test.web; 3 4 import javax.servlet.*; 5 import javax.servlet.http.HttpServletRequest ; 6 import java.io.IOException ; 7 8 35 public class TimerFilter implements Filter { 36 40 private FilterConfig config = null; 41 42 43 public void init(FilterConfig config) throws ServletException { 44 this.config = config; 45 } 46 47 48 public void destroy() { 49 config = null; 50 } 51 52 59 public void doFilter(ServletRequest request, ServletResponse response, 60 FilterChain chain) throws IOException , ServletException { 61 long before = System.currentTimeMillis(); 62 63 chain.doFilter(request, response); 65 66 long after = System.currentTimeMillis(); 67 68 String name = ""; 69 if (request instanceof HttpServletRequest ) 70 name = ((HttpServletRequest ) request).getRequestURI(); 71 72 config.getServletContext().log(name + ": " + (after - before) + "ms"); 74 } 75 } | Popular Tags |