summary of TOMCAT 5.5 configuration

本文围绕 Tomcat 5.5.11 展开,详细介绍了其多个配置文件。如 server.xml 中 Connector 和 Host 的配置;web.xml 里 servlet 调用及欢迎文件列表设置;context.xml 对默认 Web 应用的定义;{context - path}/WEB - INF/web.xml 中 servlet 及映射的定义等内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

TOMCAT version:5.5.11

$CATALINA_HOME/conf/server.xml

1.  "Connector" resides in a "Service" container. A particular instance of this component listens for connections on a specific TCP port number on the server. One or more such Connectors can be configured as part of a single Service, each forwarding to the associated Engine to perform request processing and create the response.

 "scheme" attribute: its default value is "http".

 "protocol" attribute: its default value is "HTTP/1.1".

 This example define a HTTP Connector on port 80:
<Connector port="80"
           maxHttpHeaderSize="8192"
           maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
           enableLookups="false" redirectPort="8443" acceptCount="100"
           connectionTimeout="20000" disableUploadTimeout="true" />

2.  "Host" resides in a "Service" container. The Host element represents a virtual host, which is an association of a network name for a server. In order to be effective, this name must be registered in the Domain Name Service (DNS) server

 This example defines two virtual hosts:

 <Host name="localhost" appBase="C:/public_html"
       unpackWARs="true" autoDeploy="true"
       xmlValidation="false" xmlNamespaceAware="false">
</Host>
<Host name="localtomcat" appBase="webapps"
       unpackWARs="true" autoDeploy="true"
       xmlValidation="false" xmlNamespaceAware="false">
</Host>

 And edit "C:/WINNT/SYSTEM32/DRIVERS/ETC/HOSTS" to add these two lines:

127.0.0.1       localhost
127.0.0.1       localtomcat

Then you can visit these two virtual hosts as this:

http://localhost

http://localtomcat

  $CATALINA_HOME/conf/web.xml

 1. Enable servlet invoker:

     <servlet-mapping>
        <servlet-name>invoker</servlet-name>
        <url-pattern>/servlet/*</url-pattern>
    </servlet-mapping>

 For example, if there is a servlet "myservlet" under directory "ROOT/WEB-INF/classes", you can visit it as this "http://localhost/servlet/myservlet". Enable it at developement phase. Comment it out when deploying.

 2. "welcome-file-list" defines the order to dispay welcome file. If you visit a directory without specifying file name, the welcome file will be displayed.

 In this example, "index.jsp" will be displayed, if it is found. If "index.jsp" is not found, TOMCAT will try to find "index.html".

 <welcome-file-list>
   <welcome-file>index.jsp</welcome-file>
   <welcome-file>index.html</welcome-file>
   <welcome-file>index.htm</welcome-file>
</welcome-file-list>

$CATALINA_HOME/conf/context.xml

 The contents of this file will be loaded for each virtual host(In TOMCAT document, it is said, "be loaded for each web application"). A default web application is defined in this file. Usually, we need not define a static web application.

 "docBase" attribute (also known as the Context Root) defines the directory for this web application, or the pathname to the web application archive file (if this web application is being executed directly from the WAR file). You may specify an absolute pathname for this directory or WAR file, or a pathname that is relative to the appBase directory of the owning Host. If it is not defined, "appBase/ROOT/" will be the docBase.

 "path" attribute of a web application is matched against the beginning of each request URI to select the appropriate web application for processing. Its default value is empty(""). An empty "path" defines the default web application for this Host, which will process all requests not assigned to other Contexts. We should not specify a value to "path" in this file. For example, http://localhost will invoke this default web application, and its "docBase" is "appBase/ROOT" by default.

 "reloadable" attribute: Set to true if you want Catalina to monitor classes in /WEB-INF/classes/ and /WEB-INF/lib for changes, and automatically reload the web application if a change is detected. This feature is very useful during application development, but it requires significant runtime overhead and is not recommended for use on deployed production applications.

 This example set "docBase" to "web", so when you visit http://localhost, "appBase/web/index.jsp" will be presented by default.

<Context docBase="web" reloadable="true">

    <!-- Default set of monitored resources -->
    <WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context>

 {context-path}/WEB-INF/web.xml

 1. <servlet> defines the servlets that make up your web application, including initialization parameters.

 For example, if there is a servlet "myservlet.first" under directory "{context-path}/WEB-INF/classes/myservlet/", it can be defined as this:

  <servlet>
  <servlet-name>first</servlet-name>
  <servlet-class>myservlet.first</servlet-class>
  <description>First servlet</description> 
  <load-on-startup>5</load-on-startup>
 </servlet>

2. <servlet-mapping> define mappings that are used by the servlet container to translate a particular request URI (context-relative) to a particular servlet.

 For example, map "first" to "/index.jsp". Then visiting to http://localhost/{context-path}/index.jsp will invoke the servlet of "{context-path}/WEB-INF/classes/myservlet/first".

     <servlet-mapping>
        <servlet-name>first</servlet-name>
        <url-pattern>/index.jsp</url-pattern>
    </servlet-mapping>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值