Is doFilter() executed before or after the Servlet's work is done?

前端 未结 2 599
清酒与你
清酒与你 2020-12-04 22:23

The javax.servlet.Filter object can be used both for authentication (where the Filter needs to catch the request before any servlet work needs to be done) and for XSLT trans

相关标签:
2条回答
  • 2020-12-04 22:55

    According to the servlet2.3 specification filter is performed according to web.xml configuration of filter- mapping sequence Ref-http://www.programering.com/a/MTMyADOwATI.html

    0 讨论(0)
  • 2020-12-04 23:06

    The filter chain in essence wraps the servlet invocation. The chain will process all links until it hits the "bottom", then allow the servlet to run, and then return up the chain in reverse. For example, if you have a new "example filter", your doFilter() method may look like this:

    public void doFilter(ServletRequest request,
          ServletResponse response, FilterChain chain) 
          throws IOException, ServletException {
    // do pre-servlet work here
    chain.doFilter(request, response);
    // do post servlet work here
    
    }
    
    0 讨论(0)
提交回复
热议问题