How it works

Key components in the Spring MVC architecture are shown in the following figure:

Let's look at an example flow and understand the different steps involved in executing the flow. We will take flow 4, returning ModelAndView as the specific example. The URL of flow 4 is http://localhost:8080/welcome-model-view. The different steps are detailed as follows:

  1. The browser issues a request to a specific URL. DispatcherServlet is the Front Controller, handling all requests. So, it receives the request.
  2. Dispatcher Servlet looks at the URI (in the example, /welcome-model-view) and needs to identify the right controller to handle it. To help find the right controller, it talks to the handler mapping.
  3. Handler mapping returns the specific handler method (in the example, the welcome method in BasicModelViewController) that handles the request.
  4. DispatcherServlet invokes the specific handler method (public ModelAndView welcome(ModelMap model)).
  5. The handler method returns the model and view. In this example, the ModelAndView object is returned.
  6. DispatcherServlet has the logical view name (from ModelAndView; in this example, welcome-model-view). It needs to figure out how to determine the physical view name. It checks whether there are any view resolvers available. It finds the view resolver that was configured (org.springframework.web.servlet.view.InternalResourceViewResolver). It calls the view resolver, giving it the logical view name (in this example, welcome-model-view) as the input.
  1. View resolver executes the logic to map the logical view name to the physical view name. In this example, welcome-model-view is translated to /WEB-INF/views/welcome-model-view.jsp.
  2. DispatcherServlet executes the View. It also makes the Model available to the View.
  3. View returns the content to be sent back to DispatcherServlet.
  4. DispatcherServlet sends the response back to the browser.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset