RequestDispatcher是如何实现的?

时间:2014-08-28 09:19:25

标签: java jsp tomcat servlets

我正在试图弄清楚如何实现RequestDispatcher,所以我检查了tomcat的源代码,ApplicationDispatcher类,但是有很多地方我无法理解。

我在ApplicationDispatcher类中发现用于转发请求和响应指定资源的方法是invoke(ServletRequest,ServletResponse)方法,这部分负责执行转发:

           support.fireInstanceEvent(InstanceEvent.BEFORE_DISPATCH_EVENT,   
                                  servlet, request, response);   
        // for includes/forwards   
        if ((servlet != null) && (filterChain != null)) {   
           filterChain.doFilter(request, response);   
         }   
        // Servlet Service Method is called by the FilterChain   
        support.fireInstanceEvent(InstanceEvent.AFTER_DISPATCH_EVENT,   
                                  servlet, request, response);  

我无法理解这部分代码,这是否意味着RequestDispatcher.forward()和RequestDispatcher.include()方法都在过滤链中执行?谁能告诉我tomcat的ApplicationRequestDispatcher的工作机制?

提前致谢!

0 个答案:

没有答案