First, the benefits of using spring MVC
From the MVC servlet Controller (ii), we know that to implement MVC, we're going to write a dispatcher servlet and controller class, where the dispatcher servlet will do the following work.
1. Invoke the corresponding action based on the URI.
2. Instantiate the correct controller.
3. Construct the form bean according to the request parameters.
4. Invoke the appropriate method for the Controller object.
5. Turn to a view.
In Spring MVC there is the Dispatcher Servlet, which invokes the controller's method and forwards the view. In addition to this, it has many other advantages.
Second, Spring MVC's dispatcher Servlet
Dispatcher Servlet will automatically find the configuration file under the Web-inf directory at initialization, the following naming rules for this configuration file
Servletname-servlet.xml
We can also place the configuration file somewhere else and use the Init-param element to specify the directory.
Third, controller interface
Prior to the spring mvc2.5 version, the only way to develop a controller was to implement a controller interface for spring MVC. The methods in the interface are as follows
Modelandview HandleRequest (httpservletrequest request, httpservletresponse response)
Classes that implement this interface can access the Request/response. Also be sure to return a Modelandview object that includes the picture path or view path and model name.
The implementation class of the Controller interface can handle only one action, while the annotation-based controller implements multiple request-processing actions without implement any interfaces.
Chapter III-spring MVC Introduction