MVC framework
The Spring Framework features its own MVC web application framework,
which wasn't originally planned. The Spring developers decided to write
their own Web framework as a reaction to what they perceived as the
poor design of the (then) popular Jakarta Struts Web framework,
as well as deficiencies in other available frameworks. In particular,
they felt there was insufficient separation between the presentation and
request handling layers, and between the request handling layer and the
model.Like Struts, Spring MVC is a request-based framework. The framework defines strategy
interfaces for all of the responsibilities that must be handled by a
modern request-based framework. The goal of each interface is to be
simple and clear so that it's easy for Spring MVC users to write their
own implementations, if they so choose. MVC paves the way for cleaner
front end code. All interfaces are tightly coupled to the Servlet API.
This tight coupling to the Servlet API is seen by some as a failure on
the part of the Spring developers to offer a high-level abstraction for
Web-based applications.
However, this coupling makes sure that the features of the Servlet API
remain available to developers while offering a high abstraction
framework to ease working with said API.
The DispatcherServlet class is the front controller of the framework and is responsible for delegating control to the various interfaces during the execution phases of an HTTP request.
The most important interfaces defined by Spring MVC, and their responsibilities, are listed below:
The ease of testing the implementations of these interfaces seems one important advantage of the high level of abstraction offered by Spring MVC. DispatcherServlet is tightly coupled to the Spring inversion of control container for configuring the web layers of applications. However, web applications can use other parts of the Spring Framework—including the container—and choose not to use Spring MVC.
The DispatcherServlet class is the front controller of the framework and is responsible for delegating control to the various interfaces during the execution phases of an HTTP request.
The most important interfaces defined by Spring MVC, and their responsibilities, are listed below:
- Controller: comes between Model and View to manage incoming requests and redirect to proper response. It acts as a gate that directs the incoming information. It switches between going into model or view.
- HandlerAdapter: execution of objects that handle incoming requests
- HandlerInterceptor: interception of incoming requests comparable, but not equal to Servlet filters (use is optional and not controlled by DispatcherServlet).
- HandlerMapping: selecting objects that handle incoming requests (handlers) based on any attribute or condition internal or external to those requests
- LocaleResolver: resolving and optionally saving of the locale of an individual user
- MultipartResolver: facilitate working with file uploads by wrapping incoming requests
- View: responsible for returning a response to the client. Some requests may go straight to view without going to the model part; others may go through all three.
- ViewResolver: selecting a View based on a logical name for the view (use is not strictly required)
java.util.Map
interface as a data-oriented abstraction for the Model where keys are expected to be string values.The ease of testing the implementations of these interfaces seems one important advantage of the high level of abstraction offered by Spring MVC. DispatcherServlet is tightly coupled to the Spring inversion of control container for configuring the web layers of applications. However, web applications can use other parts of the Spring Framework—including the container—and choose not to use Spring MVC.
Comments
Post a Comment