How the filter know it is before- and after-request processing?
actually it is a simple filter to record the processing time. But I am wondering how the
servlet container know it is before or after ?
Let me say, the filter is applied to /test.jsp. when users click
www.root/test.jsp, container will route the request to this filter. After finishing , it will go to next filter with chain.doFilter(..). If this is the last filter, then container will go to /test.jsp.
But , after service of /test.jsp, how the container will route the response back to this filter? if going back to this filter, how they will skip chain.doFilter(..) to the ending part of coding ?
Thanks.
------------------------------
public void doFilter(...){
long before = System.currentTimeMillis();
chain.doFilter(request, response);
long after = System.currentTimeMillis();
String name = "";
if (request instanceof HttpServletRequest) {
name = ((HttpServletRequest)request).getRequestURI();
}
config.getServletContext().log(name + ": " + (after - before) + "ms");
}