omcat目录结构及Tomcat Server处理一个http请求的过程

1.Tomcat的结构概述

    Tomcat服务器是由一系列可配置的组件构成,其核心组件是Catalina Servlet容器,它是所有其他Tomcat组件的顶层容器。Tomcat的组件可以在<CATALINA_HOME>/conf /server.xml文件中进行配置,每个Tomcat的组件在server.xml文件中对应一种配置元素.一下代码以XML的形式展示了各种 Tomcat组件之间的关系:
<Server>
    <Service>
        <Connector/>
        <Engine>
            <Host>
                <Context>
                </Context>
            </Host>
        </Engine>
    </Service>
</Server>
    在以上XML代码中,每个元素都代表一种Tomcat组件.这些元素分四类:
    1.顶层类元素    顶层类元素包括<Server>元素和<Service>元素,他们位于整个配置文件的顶层.
    2.连接器类元素    连接器类元素代表了介于客户与服务之间的通信接口,负责将客户的请求发送给服务器,并将服务器的响应结果传递给客户.
    3.容器类元素    容器类元素代表处理客户请求并生成响应结果的组件,有3种容器类元素,它们是Engine,Host和Context. Engine组件为特定的Service组件处理所有客户请求,Host组件为特定的虚拟主机处理所有客户请求,Context组件为特定的Web应用处理所有客户请求.
    4.嵌套类元素    嵌套类元素代表了可以加入到容器中的组件,如<Logger>元素、<Valve>元素和<Realm>元素,这些元素将在后面的做介绍。
    下面,再对一些基本的Tomcat元素进行介绍。如果要了解这些元素,可以参考附录A(Server.xml文件)。
    <Server>元素
    代表了整个Catalina Servlet容器,它是Tomcat实例的顶层元素.可包含一个或多个<Service>元素.
    <Service>元素
    包含一个<Engine>元素,以及一个或多个<Connector>元素,这些<Connector>元素共享同一个<Engine>元素.
    <Connector>元素
    代表和客户程序实际交互的组件,他负责接收客户请求,以及向客户返回响应结果.
    <Engine>元素
    每个<Service>元素只能包含一个<Engine>元素. <Engine>元素处理在同一个<Service>中所有<Connector>元素接收到的客户请求.
    <Host>元素
    一个<Engine>元素中可以包含多个<Host>元素.每个<Host>元素定义了一个虚拟主机,它可以包含一个或多个Web应用.
    <Context>元素
    每个<Context>元素代表了运行虚拟主机上的但个Web应用.一个<Host>元素中可以包含多个<Context>元素.
 
2. Tomcat的服务器配置文件server.xml
    Tomcat服务器是由一系列可配置的组件构成,Tomcat的组件可以在<CATALINA_HOME>\conf\server.xml 文件中进行配置,每个Tomcat组件和server.xml文件中的一种配置元素对应.下面就一些常用的元素做了介绍.关于server.xml的更多 信息,可以参考Tomcat的文档:
    <CATALINA_HOME>/webapps/tomcat-docs/config/index.html
    下面是一个server.xml文件的样例:
-----------------------------------------------------------------------------------
<!-- Example Server Configuration File -->
 
<Server port="8005" shutdown="SHUTDOWN" debug="0">
  <Service name="Catalina">
    <Connector port="8080"
               maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
               enableLookups="false" redirectPort="8443" acceptCount="100"
               debug="0" connectionTimeout="20000" 
               disableUploadTimeout="true" /> 
    <Engine name="Catalina" defaultHost="localhost" debug="0"> 
       <Logger className="org.apache.catalina.logger.FileLogger"
              prefix="catalina_log." suffix=".txt"
              timestamp="true"/> 
       <Realm className="org.apache.catalina.realm.MemoryRealm"/> 
       <Host name="localhost" debug="0" appBase="webapps"
             unpackWARs="true" >                           
           <Valve className="org.apache.catalina.valves.AccessLogValve"
                  directory="logs" prefix="localhost_access_log." suffix=".txt"
                  pattern="common" resolveHosts="false"/> 
           <Logger className="org.apache.catalina.logger.FileLogger"
                   directory="logs"  prefix="localhost_log." suffix=".txt"
                   timestamp="true"/>       
               <Context path="/sample" docBase="sample" debug="0" reloadable="true">                           
                   <Resource name="jdbc/BookDB" 
                             auth="Container"
                             type="javax.sql.DataSource"/>                                  
                   <ResourceParams name="jdbc/BookDB">                                  
                        <parameter>
                             <name>factory</name>
                             <vlaue>org.apache.commons.dbcp.BasicDataSourceFactory</value>
                        </parameter>                                         
                        <parameter>
                             <name>maxActive</name>
                             <value>100</value>
                        </parameter>                                         
                        <parameter>
                             <name>maxIdle</name>
                             <value>30</value>
                        </parameter>                                                
                        <parameter>
                             <name>maxWait</name>
                             <value>10000</value>
                        </parameter>                                         
                        <parameter>
                             <name>username</name>
                             <value>dbuser</value>
                        </parameter>                                         
                        <parameter>
                             <name>password</name>
                             <value>1234</value>
                        </parameter>                                         
                        <parameter>
                             <name>driverClassName</name>
                             <value>com.mysql.jdbc.Driver</value>
                        </parameter>                                         
                        <parameter>
                             <name>url</name>
                             <value>jdbc:mysql://localhost:3306/BookDB?autoReconnect=true</value>
                        </parameter>                                         
                  </ResourceParams>                                  
              </Context>                           
          </Host>                    
      </Engine>             
  </Service>   
  <Service name="Apache">
      <Connector prot="8009"
                 enableLookups="false" redirectPort"8443" debug="0"
                 protocol="AJP/1.3"/>                           
      <Engine name="Apache" defaultHost="localhost" debug="0">                       
          <Logger className="org.apache.catalina.logger.FileLogger"
                  prefix="apache_log." suffix=".txt"
                  timestamp="true"/>                                  
          <Realm className="org.apache.catalina.realm.MemoryRealm"/>                    
      </Engine> 
  </Service>
</Server>
 

posted on 2014-08-14 22:14  没脑子  阅读(253)  评论(0编辑  收藏  举报