1. dispatcherservlet: as a front-end controller, it is responsible for distributing customer requests to the Controller.
Its configuration in Web. XML is as follows:
<Servlet>
<Servlet-Name> dispatcherservlert </servlet-Name>
<Servlet-class> org. springframework. Web. servlet. dispatcherservlet </servlet-class>
<Init-param>
<Param-Name> contextconfiglocation </param-Name>
<Param-value> classpath: Spring. xml </param-value>
</Init-param>
</Servlet>
<Servlet-mapping>
<Servlet-Name> dispatcherservlert </servlet-Name>
<URL-pattern>/</url-pattern>
</Servlet-mapping>
2. Controller: responsible for processing customer requests and returning modelandview instances.
The controller must implement the org. springframework. EB. servlet. MVC. Controller Interface, implement the handlerequest () method in this interface, process the request in this method, and return the modelandview instance.
3. handlermapping: The dispatchservlet determines which controller processes the request based on it.
- By default, dispatcherservlet uses org. springframework. Web. servlet. handler. beannameurlhandlermapping, even if the bean instance of the controller with the same URL name as the client request is used to process the request.
- Another commonly used handlermapping is org. springframework. Web. servlet. handler. simpleurlhandlermapping. The configuration is as follows:
<Bean class = "org. springframework. Web. servlet. handler. simpleurlhandlermapping">
<Property name = "mappings">
<Props>
<Prop key = "/Add. Do"> </prop>
</Props>
</Property>
</Bean>
In the above mappings attribute settings, the key is the request URL, and the value is the bean name of the controller processing the request.
4. modelandview: Used to encapsulate the view and the model object displayed in the view.
Dispatcherservlet parses the view name based on it and processes the model object displayed in the view.
5. viewresolver: dispatcherservlet delegates viewresolver to parse the view name.
Common viewresolver instance configurations are as follows:
<! -- Process/WEB-INF/AA/all files -->
<Bean
Class = "org. springframework. Web. servlet. View. internalresourceviewresolver">
<Property name = "prefix" value = "/WEB-INF/AA/"/>
<Property name = "suffix" value = ". jsp"/>
</Bean>