01-spring MVC Overview and Configuration Dispatcherservlet

Source: Internet
Author: User

1.Spring MVC is based on MODEL2 implementation, the overall framework process such as (image from Baidu):

  

The ①web container receives an HTTP request, and if it matches the Dispatcherservlet request mapping Path (Web. xml), the container is given dispatcherservlet processing.

The ②dispatcherservlet finds the handler to process the request based on the requested information and the configuration of the handlermapping (similar to the routing feature).

③handler adapter encapsulates the Handler and calls the Handler method using a uniform method

After the ④ processor completes the business logic, it returns a Modelandview to Dispatcherservlet,modelandview that contains the view logical name and the model data information.

⑤modelandview contains the logical view name, Dispatcherservlet the parsing of the logical view to the real view by Viewresolver

⑥ The View object is real, Dispatcherservlet uses this view object to render the view of the model data in Modelandview.

The ⑦ client eventually gets HTML or PDF, and so on.

2. Configure Dispatcherservlet

    <Context-param>        <Param-name>Contextconfiglocation</Param-name>        <Param-value>Classpath:/conf/applicationcontext.xml</Param-value>    </Context-param>    <Listener>        <Listener-class>Org.springframework.web.context.ContextLoaderListener</Listener-class>    </Listener>    <servlet>        <Servlet-name>Viewspace</Servlet-name>        <Servlet-class>Org.springframework.web.servlet.DispatcherServlet</Servlet-class>        <Load-on-startup>1</Load-on-startup>    </servlet>    <servlet-mapping>        <Servlet-name>Viewspace</Servlet-name>        <Url-pattern>*.html</Url-pattern>    </servlet-mapping>

Note: Configuring Dispatcherservlet, named Viewspace, automatically loads the <servlet-name>-servlet.xml configuration file by default.

A Web. XML can be configured with multiple Dispatcherservlet to handle different requests through servlet-mapping.

If you do not want to load the default <servlet-name>-servlet.xml, you can also display the specified:

    <!--Spring MVC Servlet -    <servlet>        <Servlet-name>Springservlet</Servlet-name>        <Servlet-class>Org.springframework.web.servlet.DispatcherServlet</Servlet-class>        <Init-param>            <Param-name>Contextconfiglocation</Param-name>            <Param-value>/web-inf/spring-mvc.xml</Param-value>        </Init-param>        <Load-on-startup>1</Load-on-startup>    </servlet>

01-spring MVC Overview and Configuration Dispatcherservlet

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.