- Building Web Apps with Spring 5 and Angular
- Ajitesh Shukla
- 280字
- 2021-07-02 19:38:18
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:
- The user requests arrive at the server, and are intercepted by the Dispatcher servlet.
- 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.
- One or more instances of the HandlerInterceptor objects are retrieved from the handler object, and preprocessing logic is processed on the request object.
- 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.
- The post-processing logic on the HandlerInterceptor instances is executed. This is the final step before the rendering method is invoked.
- TheViewResolver instance is used to retrieve the appropriate view component.
- The render method is invoked on the instance of view.
推薦閱讀
- LaTeX Cookbook
- Microsoft Exchange Server PowerShell Cookbook(Third Edition)
- VMware vSphere 6.7虛擬化架構(gòu)實(shí)戰(zhàn)指南
- 劍指Java:核心原理與應(yīng)用實(shí)踐
- 前端HTML+CSS修煉之道(視頻同步+直播)
- 青少年學(xué)Python(第1冊(cè))
- Visual Foxpro 9.0數(shù)據(jù)庫(kù)程序設(shè)計(jì)教程
- Django實(shí)戰(zhàn):Python Web典型模塊與項(xiàng)目開(kāi)發(fā)
- Building Business Websites with Squarespace 7(Second Edition)
- Java RESTful Web Service實(shí)戰(zhàn)
- C++17 By Example
- MySQL數(shù)據(jù)庫(kù)應(yīng)用技術(shù)及實(shí)戰(zhàn)
- Python數(shù)據(jù)分析與挖掘?qū)崙?zhàn)(第2版)
- Mastering Linux Kernel Development
- Sony Vegas Pro 11 Beginner’s Guide