Abstract: This is the first article of “doGet method of Tomcat source code analysis”, which mainly introduces the goal and main tasks of source code analysis, and makes a very detailed introduction to the knowledge of Servlet, to help you better understand the Servlet. And why user-defined servlets need to inherit httpServlets.

Welcome to “Algorithms and the Beauty of Programming” ↑ pay attention to us!

This article was first published on the wechat official account “Beauty of Algorithms and Programming”. Welcome to follow and learn more about this series of blogs in time.

Servlets are one of the most commonly used interfaces in JavaWeb development, especially the doGet() and doPost() methods in this interface. When we are doing Web development, we often define a Servlet such as HelloServlet and have this class inherit HttpServelt, then override the doGet() method to quickly implement our own request service.

So what’s going on behind the doGet() method? The HttpServlet does a wrapper to determine the type of HTTP request and calls doGet() if it is a GET request or doPost() if it is a POST request.

What we’re looking for is not that simple answer, but what’s going on behind the scenes?

HelloServlet ->HttpServlet-> ApplicationFilterChain -> WsFilter -> StandardWrapperValve -> StandardContextValve -> StandardHostValve -> StandardEngineValve ->