Springmvc _ Data Processing Process

Source: Internet
Author: User

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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.