Explain the implementation mechanism of spring MVC dispatchservlet in detail

In spring, contextloaderlistener is just an auxiliary class. When the web container starts, it finds and creates a webapplicationcontext object, which loads the spring configuration file. The real logic implementation is actually carried out in dispatcherservlet, which is the implementation class to implement servlet interface.

Dispatcher servlet on the web The configuration in XML is as follows:

Source code analysis of dispatcher Servlet

The init() method of dispatcherservlet is implemented in httpservletbean()

init()

Onrefresh() method

When initializing the servletbean, it will eventually call the onrefresh () method, which is mainly used to refresh the global variables that spring must use in the implementation of Web functions.

Request processing logic of dispatchservlet

After the servlet receives the request, it will call the service () method, and then the service will perform the logical processing of the call response according to the request method of the HTTP response.

From the class structure, we can see that spring MVC supports get, post, put, delete, options and trace methods

From the code, we find that these methods are handed over to processrequest () to process the request.

Processrequest () - > doservice () - > dodispatch () tracks the code, and the core code for processing the request is in the dodispatch () method.

Dodispatch() method

Processdispatchresult() method

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>