Spring Framework : A Framework from SpringSource :: Spring web MVC Concept
|Spring web MVC Intro?|
- The Spring Web MVC (Model-View-Controller) framework is a robust, flexible and well designed framework used for developing loosely coupled web Applications.
- It is designed in a such a way that the development of a web is highly configurable into model, view, and controller.
- 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 appropriate model and passes it to the view for rendering.
Features of Spring Web MVC Framework
- Powerful configuration of framework and application classes
- Easier testing
- No need of duplication of code
- Validation and binding
- Model transfer flexibility
- Facility of form tag library
Component of Spring Web MVC Framework
- The DispatcherServlet class
- The HandlerMapping interface
- Spring Web MVC Controller
- The ModelAndView class
- The ViewResolver interface
- The View components
|Spring web MVC Architecture|
The DispatcherServlet class
- This class is an important part of the Spring Web MVC framework.
- It is used for intercepting the incoming requests and determines which controller handles the request.
- It is fully configured with IoC such as Spring Context, Spring ORM, Spring DAO.
- It is a servlet that is inherited from HttpServlet.
Following is the flow of events corresponding to an incoming HTTP request to DispatcherServlet:
- After receiving an HTTP request, DispatcherServlet consults the HandlerMapping to call 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.
- The DispatcherServlet will take help from ViewResolver to pickup the defined view for the request.
- Once view is finalized, The DispatcherServlet passes the model data to the view which is finally rendered on the browser.
- All the above mentioned components ie. HandlerMapping, Controller and ViewResolver are parts of WebApplicationContext which is an extension of the plain ApplicationContext with some extra features necessary for web applications.
|Spring web MVC Example|
Project Structure used in this example
lib Files used in this example
Welcome Page below
Click Below to download the Examples