×
☰ See All Chapters

Spring MVC Architecture

The following diagram shows the spring MVC architecture starting from the point of user sending a request to HTTP server till the response is returned back to user.

spring-mvc-architecture-0
 

Spring MVC Architecture flow

Below steps explains the request and response flow:

  1. DispatcherServlet receives the request. 

  2. DispatcherServlet dispatches the task of selecting an appropriate controller to HandlerMapping. HandlerMapping selects the controller which is mapped to the incoming request URL and returns the (selected Handler) Controller to DispatcherServlet. 

  3. DispatcherServlet dispatches the task of executing of business logic of Controller to HandlerAdapter. 

  4. HandlerAdapter calls the business logic process of Controller. 

  5. Controller executes the business logic, sets the processing result in Model and returns the logical name (or directly the name of the JSP) to HandlerAdapter. 

  6. DispatcherServlet dispatches the task of resolving the view (JSP/ Velocity/ FreeMarker etc. or implementation of View interface) corresponding to the View name to ViewResolver which returns the view (JSP/implementation of View interface) mapped to View name. 

  7. DispatcherServlet dispatches the rendering process to returned  view (JSP/ implementation of View interface) 

  8. View (JSP/ implementation of View interface) renders Model data and returns the response. 

DispatcherServlet is the central Servlet that dispatches requests to controllers. Now let us learn step by step flow of request processing in spring MVC. In Spring MVC DispatcherServlet dispatches the task of selecting an appropriate controller to HandlerMapping. HandlerMapping selects the controller which is mapped to the incoming request URL and returns the (selected Handler) Controller to DispatcherServlet. In spring MVC applications the name of spring bean configuration file should be <logical name of DispatcherServlet in web.xml>-servlet.xml

 


All Chapters
Author