Spring MVC
Spring MVC Components
---------------------
1) Front Controller (DispatcherServlet)
2) Handler Mapper
3) Controller
4) ModelAndView
5) ViewResolver
6) View
-> Spring MVC module is part of Spring framework
-> In Spring 1.x version we have Spring MVC and Spring Web MVC modules
-> Spring 2.x version web module and mvc module are combined and released Spring Web MVC module
-> Spring MVC module is used to develop below types of applications
a) Web applications
b) Distributed applications
-> This Spring Web MVC module is developed based on 2 design patterns
a) MVC Design Pattern
b) Front Controller Design Pattern
FrontController
---------------
-> FrontController is responsible to perform pre- processing and post processing of incoming request
-> For example capturing form data we can consider as pre-processing request
-> For example sending response back to client in client understandable form can be called as Post Processing of request
-> In Spring Web MVC based application we will use DispatcherServlet as a front controller
-> DispatcherServlet is a pre-defined servlet provided by Spring MVC module
-> Dispatcher will be called as Spring framework Servlet
Handler Mapper
--------------
-> Handler Mapper is a pre-defined class available in Spring MVC
-> Handler Mapper is responsible to identify request handler(Controller)
-> The program which is handling incoming request is called as Request Handler
-> Controllers will be called as request handlers
-> Handler Mapper will identify request handler and returns handler details to DispatcherServlet
Controller
----------
-> Controller is a program which is responsible to handle request
-> Using Spring MVC module we can create our own Controllers
-> In Spring MVC some predefined controller classes are available like below
a)SimpleFormController
b)AbstractCommandController
c)MultiActionController etc...
-> We can create User define controller using @Controller annotation
ModelAndView
------------
-> Once Request processing is completed Controller will return ModelAndView object to DispatcherServlet
-> ModelAndView is a pre-defined class available in Spring MVC module
-> In ModelAndView class, model represents data and view represents logical view name
Model -----> Holds Data
View ------> Logical view file name
View Resolver
-------------
-> In Spring MVC we have multiple view resolver classes+
a)InternalResourceViewResolver
b)URLBasedViewResolver
c)XmlViewResolver etc....
-> These view resolvers are responsible to identify view files (location & extension)
View Component
----------------
-> It is responsible to render model data on view file
1) Incoming Http Request will be recieved by DispatcherServlet. DS is a predefined Servlet class in Spring MVC and it is acting as Front Controller.
2) DispatcherServlet will send requested URL to HandlerMapper
3) HandlerMapper will identify request handler which is responsible to handle this request and will send request handler details to DispatcherServlet.
4) DispatcherServlet will call respective Controller class method
5) Controller method will process request and will send ModelAndView object to DispatcherServlet
Model ---> Data
View ---> Logical File Name
6) DispatcherServlet will send view name to ViewResolver
7) ViewResolver will identify view location & extension and sends data to DispatcherServlet
8) DispatcherServlet will give model and view details to View Component
9) Model data will be rendered on view sends back to DispatcherServlet
10) DispatcherServlet will send response back for the recieved request