天天看點

tomcat如何處理請求

當我們在位址欄輸入:http://localhost:8080/test/index.jsp時,tomcat是如何處理的呢.

1、該請求首先被8080端口獲得,然後将該請求交給監聽在該端口的http1.1 Connector

2、Connector将該請求轉交給service下的engine,并等待engine的請求回應

3、engine獲得請求 然後與engine下所有的虛拟host進行比對,得到主機localhost

4、在localhost下比對/test的Context

5、比對上Context後,再比對/index.jsp

6、構造HttpServletRequest和HttpServletResponse對象,并根據請求方法調用doGet(),doPost()方法.HttpServletRequest,HttpServletResponse為方法參數

7、獲得請求相應HttpServletResponse,并将請求相應交給localhost

8、localhost得到相應後,轉交給engine

9、engine将請求轉交給Connector

10、Connector将請求相應交給用戶端browser