☰ 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 flow
Below steps explains the request and response flow:
DispatcherServlet receives the request.
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.
DispatcherServlet dispatches the task of executing of business logic of Controller to HandlerAdapter.
HandlerAdapter calls the business logic process of Controller.
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.
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.
DispatcherServlet dispatches the rendering process to returned view (JSP/ implementation of View interface)
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