Sung in Blog

                     一些技術(shù)文章 & 一些生活雜碎

          1 - Tomcat Server的組成部分

          1.1 - Server

          A Server element represents the entire Catalina servlet container. (Singleton)

          1.2 - Service

          A Service element represents the combination of one or more Connector components that share a single Engine
          Service是這樣一個集合:它由一個或者多個Connector組成,以及一個Engine,負責處理所有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 - Engine

          The Engine element represents the entire request processing machinery associated with a particular Service
          It receives and processes all requests from one or more Connectors
          and returns the completed response to the Connector for ultimate transmission back to the client
          Engine下可以配置多個虛擬主機Virtual Host,每個虛擬主機都有一個域名
          當Engine獲得一個請求時,它把該請求匹配到某個Host上,然后把該請求交給該Host來處理
          Engine有一個默認虛擬主機,當請求無法匹配到任何一個Host上的時候,將交給該默認Host來處理

          1.5 - Host

          代表一個Virtual Host,虛擬主機,每個虛擬主機和某個網(wǎng)絡(luò)域名Domain Name相匹配
          每個虛擬主機下都可以部署(deploy)一個或者多個Web App,每個Web App對應(yīng)于一個Context,有一個Context path
          當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類
          當Context獲得請求時,將在自己的映射表(mapping table)中尋找相匹配的Servlet類
          如果找到,則執(zhí)行該類,獲得請求的回應(yīng),并返回

          2 - Tomcat Server的結(jié)構(gòu)圖

          3 - 配置文件$CATALINA_HOME/conf/server.xml的說明

          該文件描述了如何啟動Tomcat Server

          
          
          
          
          
          
          
          
          
          
            
          
            
            
          
          
            
          
            
              ... ... ... ...
            
          
          
            
          
            
          
          
              
          
              
          
          
              
          
              
              
          
                
          
                
          
                
          
                
          
          
                
          
                
                
          
                  
          
                  
                
          
                  
          
                  
                  
          
                  
          
                  
                       
                  
                
                
              
          
            
          
          
          
          
          
          
          

          4 - Context的部署配置文件web.xml的說明

          一個Context對應(yīng)于一個Web App,每個Web App是由一個或者多個servlet組成的
          當一個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)
          當該Context獲得請求時,將查詢mapping table,找到被請求的servlet,并執(zhí)行以獲得請求回應(yīng)

          分析一下所有的Context共享的web.xml文件,在其中定義的servlet被所有的Web App載入

          
          
          
          
          
          
          
            
          
          
          
            
            
            
          
            
          
            
          
              
                  default
                  
                    org.apache.catalina.servlets.DefaultServlet
                  
                  
                      debug
                      0
                  
                  
                      listings
                      true
                  
                  1
              
          
          
            
          
              
                  invoker
                  
                    org.apache.catalina.servlets.InvokerServlet
                  
                  
                      debug
                      0
                  
                  2
              
          
          
            
          
              
                  jsp
                  org.apache.jasper.servlet.JspServlet
                  
                      logVerbosityLevel
                      WARNING
                  
                  3
              
          
          
          
            
            
            
          
              
              
                  default
                  /
              
          
              
                  invoker
                  /servlet/*
              
          
              
                  jsp
                  *.jsp
              
          
          
            
            
            
          
              ... ... ... ...
          
          
          
          
          
          
          

          5 - Tomcat Server處理一個http請求的過程

          假設(shè)來自客戶的請求為:
          http://localhost:8080/wsota/wsota_index.jsp

          1) 請求被發(fā)送到本機端口8080,被在那里偵聽的Coyote HTTP/1.1 Connector獲得
          2) Connector把該請求交給它所在的Service的Engine來處理,并等待來自Engine的回應(yīng)
          3) Engine獲得請求localhost/wsota/wsota_index.jsp,匹配它所擁有的所有虛擬主機Host
          4) Engine匹配到名為localhost的Host(即使匹配不到也把請求交給該Host處理,因為該Host被定義為該Engine的默認主機)
          5) localhost Host獲得請求/wsota/wsota_index.jsp,匹配它所擁有的所有Context
          6) Host匹配到路徑為/wsota的Context(如果匹配不到就把該請求交給路徑名為""的Context去處理)
          7) path="/wsota"的Context獲得請求/wsota_index.jsp,在它的mapping table中尋找對應(yīng)的servlet
          8) Context匹配到URL PATTERN為*.jsp的servlet,對應(yīng)于JspServlet類
          9) 構(gòu)造HttpServletRequest對象和HttpServletResponse對象,作為參數(shù)調(diào)用JspServlet的doGet或doPost方法
          10)Context把執(zhí)行完了之后的HttpServletResponse對象返回給Host
          11)Host把HttpServletResponse對象返回給Engine
          12)Engine把HttpServletResponse對象返回給Connector
          13)Connector把HttpServletResponse對象返回給客戶browser

          1 - Tomcat Server的組成部分

          1.1 - Server

          A Server element represents the entire Catalina servlet container. (Singleton)

          1.2 - Service

          A Service element represents the combination of one or more Connector components that share a single Engine
          Service是這樣一個集合:它由一個或者多個Connector組成,以及一個Engine,負責處理所有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 - Engine

          The Engine element represents the entire request processing machinery associated with a particular Service
          It receives and processes all requests from one or more Connectors
          and returns the completed response to the Connector for ultimate transmission back to the client
          Engine下可以配置多個虛擬主機Virtual Host,每個虛擬主機都有一個域名
          當Engine獲得一個請求時,它把該請求匹配到某個Host上,然后把該請求交給該Host來處理
          Engine有一個默認虛擬主機,當請求無法匹配到任何一個Host上的時候,將交給該默認Host來處理

          1.5 - Host

          代表一個Virtual Host,虛擬主機,每個虛擬主機和某個網(wǎng)絡(luò)域名Domain Name相匹配
          每個虛擬主機下都可以部署(deploy)一個或者多個Web App,每個Web App對應(yīng)于一個Context,有一個Context path
          當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類
          當Context獲得請求時,將在自己的映射表(mapping table)中尋找相匹配的Servlet類
          如果找到,則執(zhí)行該類,獲得請求的回應(yīng),并返回

          2 - Tomcat Server的結(jié)構(gòu)圖

          3 - 配置文件$CATALINA_HOME/conf/server.xml的說明

          該文件描述了如何啟動Tomcat Server

          
          
          
          
          
          
          
          
          
          
            
          
            
            
          
          
            
          
            
              ... ... ... ...
            
          
          
            
          
            
          
          
              
          
              
          
          
              
          
              
              
          
                
          
                
          
                
          
                
          
          
                
          
                
                
          
                  
          
                  
                
          
                  
          
                  
                  
          
                  
          
                  
                       
                  
                
                
              
          
            
          
          
          
          
          
          
          

          4 - Context的部署配置文件web.xml的說明

          一個Context對應(yīng)于一個Web App,每個Web App是由一個或者多個servlet組成的
          當一個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)
          當該Context獲得請求時,將查詢mapping table,找到被請求的servlet,并執(zhí)行以獲得請求回應(yīng)

          分析一下所有的Context共享的web.xml文件,在其中定義的servlet被所有的Web App載入

          
          
          
          
          
          
          
            
          
          
          
            
            
            
          
            
          
            
          
              
                  default
                  
                    org.apache.catalina.servlets.DefaultServlet
                  
                  
                      debug
                      0
                  
                  
                      listings
                      true
                  
                  1
              
          
          
            
          
              
                  invoker
                  
                    org.apache.catalina.servlets.InvokerServlet
                  
                  
                      debug
                      0
                  
                  2
              
          
          
            
          
              
                  jsp
                  org.apache.jasper.servlet.JspServlet
                  
                      logVerbosityLevel
                      WARNING
                  
                  3
              
          
          
          
            
            
            
          
              
              
                  default
                  /
              
          
              
                  invoker
                  /servlet/*
              
          
              
                  jsp
                  *.jsp
              
          
          
            
            
            
          
              ... ... ... ...
          
          
          
          
          
          
          

          5 - Tomcat Server處理一個http請求的過程

          假設(shè)來自客戶的請求為:
          http://localhost:8080/wsota/wsota_index.jsp

          1) 請求被發(fā)送到本機端口8080,被在那里偵聽的Coyote HTTP/1.1 Connector獲得
          2) Connector把該請求交給它所在的Service的Engine來處理,并等待來自Engine的回應(yīng)
          3) Engine獲得請求localhost/wsota/wsota_index.jsp,匹配它所擁有的所有虛擬主機Host
          4) Engine匹配到名為localhost的Host(即使匹配不到也把請求交給該Host處理,因為該Host被定義為該Engine的默認主機)
          5) localhost Host獲得請求/wsota/wsota_index.jsp,匹配它所擁有的所有Context
          6) Host匹配到路徑為/wsota的Context(如果匹配不到就把該請求交給路徑名為""的Context去處理)
          7) path="/wsota"的Context獲得請求/wsota_index.jsp,在它的mapping table中尋找對應(yīng)的servlet
          8) Context匹配到URL PATTERN為*.jsp的servlet,對應(yīng)于JspServlet類
          9) 構(gòu)造HttpServletRequest對象和HttpServletResponse對象,作為參數(shù)調(diào)用JspServlet的doGet或doPost方法
          10)Context把執(zhí)行完了之后的HttpServletResponse對象返回給Host
          11)Host把HttpServletResponse對象返回給Engine
          12)Engine把HttpServletResponse對象返回給Connector
          13)Connector把HttpServletResponse對象返回給客戶browser

          ]]>
          posted on 2005-09-20 15:06 Sung 閱讀(387) 評論(0)  編輯  收藏 所屬分類: Tomcat
          主站蜘蛛池模板: 溧水县| 河北省| 徐汇区| 军事| 沂南县| 尚义县| 柳州市| 南郑县| 泰顺县| 鄢陵县| 东阿县| 哈尔滨市| 高安市| 来安县| 玉树县| 甘孜县| 南丹县| 靖安县| 特克斯县| 清河县| 云龙县| 沂水县| 文水县| 新晃| 巫溪县| 呼和浩特市| 平泉县| 上饶市| 承德市| 武宁县| 皋兰县| 怀仁县| 鲁山县| 宣威市| 柳河县| 宜丰县| 德庆县| 延长县| 新平| 安西县| 离岛区|