We understand what MVC design pattern is, it will be easy to understand spring MVC framework. Spring Web MVC framework is basically designed to provide support for web architecture to develop enterprise level application with minimum efforts on initial web architecture.
Spring MVC is designed around two components DispatcherServlet and @Component annotation. DispatcherServlet is basically centralized dispatcher which redirects any requests coming to the appropriate Spring Framework handlers. @Controller annotation is default handler for request and response.
A Controller is basically a handler which handles user requests and response. It is responsible to prepare a data Model which can be used by the view. Means it prepares a Model Map with some.
Let’s understand the working of Spring MVC framework
User enters some URL in browser to make some request to server.
Request goes to DispatcherServlet which actually is front controller. DispatcherServlet is configured in web.xml. DispatcherServlet reads the request mappings in configuration file or annotated Controller list with help of Handler Adapter and dispatch it to the appropriate controller. Handler mappings map the request to appropriate controller.
A Controller then reads the client request and process the request with the help of Business Logic defined in controller method. After processing the request, controller prepares the ModelAndView object.
This ModelAndView object is then passed back to the front controller. Based on value passed in ModelAndView controller resolves the view that can be JSP file or some template configured.
Based on the input, View is rendered and passed back to the user screen.