SPRINGMVC Working principle 2 (detailed code)

Source: Internet
Author: User

          

                           Figure 1. Flowchart

1. When a request comes in and enters Dispatcherservlet, there is a method called the Dodispatch () method that contains the core process

The source code is as follows:

4. Then look down at gethandler (): (Dispatcherservlet. Java)

Mapperhandler is the Handlerexecutionchain (processor call chain) class.

The Handlerexecutionchain contains Processor objects and processor-related interceptors, with target methods and handler.


Handlermapping gets the source code of the Handlerexecutionchina object 1120 lines (Dispatcherservlet.java).

Here, the 1115-row handlermapping defines the mapping between the request to the processor, and the request to find the processor requires handlermapping.

5. After executing the above code, return to line 932 and proceed with the following:

There are three scenarios:

One, when the URL path of the request does not exist (there is no corresponding requestmapping annotation method)

If the mapping of the outgoing request is empty. The returned Handlerexecutionchain, Mappedhandler object is empty to indicate that there is no corresponding mapping

Execute the nohandlerfound method


This means that there is no page and will go to the 404 error page .

Second, when the requested path URL does not exist (there is no corresponding requestmapping annotation method), the following annotations exist in Applicationcontext.xml:

After the above configuration is GetHandler () is not NULL, because with the above configuration, will call simpleurlhandlermapping to find local static resources, such as CSS, JS, etc. but the same path does not exist jump to 404 page.

Third, if there is a mapping, continue to execute after the code:

6. Execute to the above line Gethandleradapter ():

Handleradapter (Handler adapter)

This class does a lot of work, such as assigning a form to an entity bean, and binding the data through Binner.

7. Continue execution: 954 lines prehandle ().

Here, the underlying call to the Interceptor's Prehandle method:

8. Then proceed to the Code 959 Line (Dispatcherservlet.java),handle () method.

Here it returns a Modelandview, if shown.

9. The code then proceeds to execute the call to the Interceptor . Posthandler () method, and then call the Processdispatchresult method, such as:

Continue execution

Then proceed to code 1027 line (Dispatcherservlet.java)

Here is the render () method already in rendered view

This is done by referencing the view parser configured in Applicationcontext.xml and then forwarding the page.

The above Rd.forward is forwarded and the whole process is gone!!!

SPRINGMVC Working principle 2 (detailed code)

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.