(基于tomcat 5.0.28)

A Container is an object that can execute requests received from a client, and return responses based on those requests. A Container may optionally support a pipeline of Valves that process the request in an order configured at runtime, by implementing the Pipeline interface as well.
Containers will exist at several conceptual levels within Catalina. The following examples represent common cases:
Engine - Representation of the entire Catalina servlet engine, most likely containing one or more subcontainers that are either Host or Context implementations, or other custom groups.
Host - Representation of a virtual host containing a number of Contexts.
Context - Representation of a single ServletContext, which will typically contain one or more Wrappers for the supported servlets.
Wrapper - Representation of an individual servlet definition (which may support multiple servlet instances if the servlet itself implements SingleThreadModel).
A given deployment of Catalina need not include Containers at all of the levels described above. For example, an administration application embedded within a network device (such as a router) might only contain a single Context and a few Wrappers, or even a single Wrapper if the application is relatively small. Therefore, Container implementations need to be designed so that they will operate correctly in the absence of parent Containers in a given deployment. (此處摘自Container的javadoc)

Container - 執行來自客戶的request,并生起相應的response. container可以通過 pipleline 和 valvel 來實現執行時的rquest動態處理,container也可以自己實現 Pipeline接口。
Container的概念覆蓋Catalina的幾個其他結構層次,比如下面的幾個例子:
Engine - 代表了整個 Catalina servlet engine, 一般包括幾個子 container,比如 Host, Context,或其他的一些配置
Host - 代表了一個包含Context的虛擬Host,
Wrapper - 代表某個特定servlet得實現(此實現可以僅僅是一個servlet的實例,或者如果此servlet實現了SingleTreadModel,可以是多個servlet)
一個特定的Catalina部署不必包含所有上面描述的container。比如說一個特殊的內嵌在網絡設備上(比如路由器)的管理應用程序,可以只包含單獨的一個context和很少的幾個Wrapper, 或者是干脆只有一個Wrapper。因此,在實現container時要考慮到也許他們會在沒有父container的環境中運行。

Engine - 代表了整個 Catalina servlet engine。
Engine的子container一般會是Host,或者 Context.
Engine總是在Catalina 的container 中最頂的一個Container, 所以Engine的 setParent方法拋出一個IllegalArgumentException異常。

Host - 代表了一個包含Context的虛擬Host,比如localhost 或者
http://www.yourdomain.com/等等
Host的父Container一般是engine或者為空
Host的子Container一般是Context,代表一個部署在此Host上的一個特定的應用。
 在server.xml中context可能會有如下的對應
 <Host name="
http://www.yourdomain.com/" debug="0" unpackWARs="true" autoDeploy="true" xmlValidation="false" >
       ......
 </Host>
      
Context- Context 也是一個Container,它代表了Host 下的一個特定的應用(web application),context的父Container通常是Host,子Container通常是Wrapper. 在server.xml中context可能會有如下的對應
 <Context path="/ctxpath" docBase="d:\docbase" workDir="d:\workdir" />

Wrapper - Wrapper 代表某個特定servlet得實現,它也是一個Container. Wrapper 負責裝載,初始化,銷毀其所對應的 servlet。 它的父Container通常是Context. web.xml中的servlet定義對應相應的wrapper. Wrapper 沒有子container.

Connector-負責接受來自客戶端的request,并返回response到客戶端。比如coyote 是一個http connector,它復雜接受http請求,
也可以有一個ftp connector, 負責處理ftp請求。

Service 是一組共享同一個container(比如engine)的connector.比如一個service中可以有處理ssl-http請求和non-ssl-http的Connctor,它們共享同一個Container


valve - 是屬于特定Container的專門處理request的組件。一個特定container中會有多個valve,他們在container的pipeline中。在處理request時被依次調用。

pipeline,屬于特定container的, valve的集合。 在處理request時,pipeline中的request會被依次調用。每個container一般都有特定的一個valve生成最終返回給用戶的response(其他的valve也許只是對request或response作一些檢查或設置),這個valve在pipeline中最后被執行。因此,在pipeline的實現中,有一個setBasic()方法,就是設置這個特定的valve 的。與 engine對應的這個basic valve 是StandardEngineValue, Host對應的是 StandardHostPipeLine. 大多數情況下,每個Container只有一個basic valve.

以上的幾個概念一般在server.xml和web.xml中都有對應。

一般來講,一個簡單的catalina實現就是最頂層一個server, 之后是一個service,其中包括兩個結構上并列的的組件,connctor,和engine.(connector 接受請求,engine處理請求). engine 下面是Host,   Host 下面是 Context, Context下面是Wrapper,最下面是 servlet.