官术网_书友最值得收藏!

Introduction to the Dispatcher servlet

In this section, we will learn about the core component of a Spring web MVC application, the Dispatcher servlet.

As introduced in the previous section, Dispatcher servlet is the front controller which processes the user requests by invoking the appropriate components such as handler mappings, interceptors, adapters, custom controllers, services, DOA, view resolver, and finally, the views. The following diagram represents the web request/response workflow of the Dispatcher servlet:

Figure 4: Web request/response flow across the Dispatcher servlet

As per the preceding diagram, the journey of a request/response through a Spring web MVC application looks like the following:

  1. The user requests arrive at the server, and are intercepted by the Dispatcher servlet.
  2. The Dispatcher servlet gets a handler object (primarily, an instance of HandlerExecutionChain) from the HandlerMapping object based on the URL mapping. URL mappings can be defined with the web.xml file or as annotations on the Controllers' methods.
  1. One or more instances of the HandlerInterceptor objects are retrieved from the handler object, and preprocessing logic is processed on the request object.
  2. The instance of HandlerAdapter is retrieved from the handler object, and the handle method is invoked. This results in execution of logic within the controller class. In the preceding diagram (Figure 3), the request with RequestMapping as "/" leads to the execution of code within the home method as part of this step.  
  3. The post-processing logic on the HandlerInterceptor instances is executed. This is the final step before the rendering method is invoked. 
  4. TheViewResolver instance is used to retrieve the appropriate view component.
  5. The render method is invoked on the instance of view.
主站蜘蛛池模板: 竹北市| 资溪县| 曲水县| 剑阁县| 阳东县| 庆阳市| 德化县| 平远县| 若尔盖县| 丁青县| 麻栗坡县| 望都县| 卢龙县| 清徐县| 河北省| 手机| 吉木萨尔县| 浦江县| 蕲春县| 林周县| 岑溪市| 台前县| 崇明县| 玛纳斯县| 荔波县| 全南县| 乌兰浩特市| 航空| 博罗县| 门头沟区| 双牌县| 靖远县| 定远县| 万山特区| 垦利县| 江川县| 平泉县| 台前县| 泸西县| 嘉义县| 浮山县|