Spring MVC Introduction and Flow

 

Spring MVC is based on the very famous architecture MVC i.e.  three parts Model ,View and Controller . But the hero of this movie is some one else which is Dispatcher servlet .


So , in very simple words we can define these three parts as :

Model – You can Say POJO classes in you r application .

View –  jsp ,html and other presentable content of your application .

Controller – is also a java class but as the name specify it control the whole application flow means it handles the user request and decide what to do next ?


So why did I say that Dispatcher servlet is the hero ? It should be controller

Dispatcher servlet is the first thing in our application to which our request hits and then it is decided further that which controller will work upon it . So Dispatcher servlet is the hero of movie .

SpringMVCFLow


Now let us move to the whole flow of Spring MVC application .

1. When a user make a request to Spring MVC application it first goes o Dispatcher servlet .

2.Dispatcher Servlet is defined in web.xml of an application .This is the very first servlet invoked in an application.

3. Then ,Dispatcher Servlet asks Handler Mapper that which controller needs to be invoke for this particular request .

4. Handler Mapper invokes the appropriate Controller.

5. Now the controller takes  request and invokes the appropriate  GET or POST method and populates model data using the business logic defined and return the view name to Dispatcher Servlet .

6. Dispatcher Servlet take that view name and take help of view resolver to find the exact directory structure of the view i.e. jsp or html page .

7. At the end when view is resolved the model data is passed by Dispatcher Servlet to the View .

8. And now User can see the response of the request sent means the View is the response.

1 comments:

I think this is the best article today. Thanks for taking your own time to discuss this topic, I feel happy about that curiosity has increased to learn more about this topic. Keep sharing your information regularly for my future reference.
Java Courses in chennai

Reply

Post a Comment