What is Spring MVC?


What is Spring MVC?


The Spring Web MVC framework provides Model-View-Controller (MVC) architecture and ready components that can be used to develop flexible and loosely coupled web applications. The MVC pattern results in separating the different aspects of the application (input logic, business logic, and UI logic), while providing a loose coupling between these elements.


  • 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.


Spring is an open source framework which will help developers to build robust enterprise applications with minimal effort. Spring comes with a default Controller to handle the incoming requests. You can even customize its behavior. View is related to the presentation layer and depending on the business need, developers can choose from several UI Technologies like JSP, DHTML, PDF… etc, Model holds the data which needs to be processe and passed between view and Controller Helper classes.

Flow Of Spring MVC:


Spring MVC and Spring-Web-Flow both are different modules of Spring framework. If we talk about the Spring layered structure then Spring web flow is built on top of Spring MVC. Spring MVC is an architectural pattern which differentiates between Model, View and Controller and is used to make web applications. Spring Web Flow determines the entry and exit of flow. It is the flow system which defines the flow of control and execution for a request starting from the Dispatcher servlet to the view display. Dispatcher Servlet and MVC both are present in the framework, but the path which defines which controller of MVC will come into action is given by the web flow system.


As Spring web flow is built on top of MVC it uses MVC pattern to determine the flow. Spring MVC makes it easy to build any web application as we have just written the logic and not care about maintenance which is done by the framework itself. Also, the separation of Model, View and Controller makes it comfortable and easier for a developer.


                               


An incoming HTTP request to DispatcherServlet is handled in the following manner :


1. After receiving an HTTP request, DispatcherServlet consults the HandlerMapping to call the appropriate Controller.


2. The Controller takes the request and calls the appropriate method based on whether it is a GET or POST request. This method sets up the model data based on the business logic and returns it along with the name of the view to the DispatcherServlet.


3. The DispatcherServlet with the help of the ViewResolver figures out the view for the request.


4. Finally, the DispatcherServlet passes the model data to the view and the view renders it on the browser.


Thanks for reading the post.



Comments