1 - Tomcat Server的組成部分1.1 - ServerA Server element rePResents the entire Catalina servlet container. (Singleton)1.2 - ServiceA Service element represents the combination of one or more Connector components that share a single EngineService是這樣一個集合:它由一個或者多個Connector組成,以及一個Engine,負責(zé)處理所有Connector所獲得的客戶請求1.3 - Connector一個Connector將在某個指定端口上偵聽客戶請求,并將獲得的請求交給Engine來處理,從Engine處獲得回應(yīng)并返回客戶TOMCAT有兩個典型的Connector,一個直接偵聽來自browser的http請求,一個偵聽來自其它WebServer的請求Coyote Http/1.1 Connector 在端口8080處偵聽來自客戶browser的http請求Coyote JK2 Connector 在端口8009處偵聽來自其它WebServer(Apache)的servlet/jsp代理請求1.4 - EngineThe Engine element represents the entire request processing machinery associated with a particular ServiceIt receives and processes all requests from one or more Connectorsand returns the completed response to the Connector for ultimate transmission back to the clientEngine下可以配置多個虛擬主機Virtual Host,每個虛擬主機都有一個域名當(dāng)Engine獲得一個請求時,它把該請求匹配到某個Host上,然后把該請求交給該Host來處理Engine有一個默認虛擬主機,當(dāng)請求無法匹配到任何一個Host上的時候,將交給該默認Host來處理1.5 - Host代表一個Virtual Host,虛擬主機,每個虛擬主機和某個網(wǎng)絡(luò)域名Domain Name相匹配每個虛擬主機下都可以部署(deploy)一個或者多個Web App,每個Web App對應(yīng)于一個Context,有一個Context path當(dāng)Host獲得一個請求時,將把該請求匹配到某個Context上,然后把該請求交給該Context來處理匹配的方法是“最長匹配”,所以一個path==""的Context將成為該Host的默認Context所有無法和其它Context的路徑名匹配的請求都將最終和該默認Context匹配1.6 - Context一個Context對應(yīng)于一個Web application,一個Web Application由一個或者多個Servlet組成Context在創(chuàng)建的時候?qū)⒏鶕?jù)配置文件$CATALINA_HOME/conf/web.xml和$WEBAPP_HOME/WEB-INF/web.xml載入Servlet類當(dāng)Context獲得請求時,將在自己的映射表(mapping table)中尋找相匹配的Servlet類如果找到,則執(zhí)行該類,獲得請求的回應(yīng),并返回2 - Tomcat Server的結(jié)構(gòu)圖

3 - 配置文件$CATALINA_HOME/conf/server.xml的說明該文件描述了如何啟動Tomcat Server4 - Context的部署配置文件web.xml的說明一個Context對應(yīng)于一個Web App,每個Web App是由一個或者多個servlet組成的當(dāng)一個Web App被初始化的時候,它將用自己的ClassLoader對象載入“部署配置文件web.xml”中定義的每個servlet類它首先載入在$CATALINA_HOME/conf/web.xml中部署的servlet類然后載入在自己的Web App根目錄下的WEB-INF/web.xml中部署的servlet類web.xml文件有兩部分:servlet類定義和servlet映射定義每個被載入的servlet類都有一個名字,且被填入該Context的映射表(mapping table)中,和某種URL PATTERN對應(yīng)當(dāng)該Context獲得請求時,將查詢mapping table,找到被請求的servlet,并執(zhí)行以獲得請求回應(yīng)分析一下所有的Context共享的web.xml文件,在其中定義的servlet被所有的Web App載入5 - Tomcat Server處理一個http請求的過程假設(shè)來自客戶的請求為:http://localhost:8080/wsota/wsota_index.jsp
轉(zhuǎn)自:http://blog.sina.com.cn/s/blog_7cc931cb01014r6n.html
新聞熱點
疑難解答