Saturday, September 9, 2017

Spring MVC : The Framework - Part 1

What is Spring-MVC ?


Spring-MVC is a framework that offers Model-View-Controller Architecture to build loosely coupled and flexible web-applications. MVC Pattern separates the concerns of Business-Logic, Model and UI components so that  can evolve themselves without distracting other components.  Lets take a look at what is actually Model-View-Controller in this architecture.

  • The Model encapsulates the application data and in general they will consist of POJO.
  • The View is responsible for rendering the model data and in general it generates HTML output that the client's browser can interpret.
  • The Controller is responsible for processing user requests and building an appropriate model and passes it to the view for rendering.


Dispatcher-Servlet : What is happening ?


Whole Spring-MVC framework is build around the Dispatcher-Servlet  which handles HTTP Requests and HTTP Responses. It more likely to be the Global-Handler in Spring-MVC. The following diagram is to explain the request-handling-process of Spring-MVC.


After receiving an HTTP request, Front-Controller (DispatcherServlet) consults the handler-mappings and calls the appropriate controller. 

The Controller takes the request and calls the appropriate service methods based on used GET or POST method. The service method will set model data based on defined business logic and returns view name to the DispatcherServlet. 

Then Front-Controller checks with the view-resolver to find out which 'view' it should render back to the User. When the 'View' is selected, it binds the Modal data to the View and renders it.






No comments:

Post a Comment