Jakarta-Tomcat Simplified Chinese version User Guide Part 2
Element and description
Server
The most important element in the server. xml file. Server defines a Tomcat Server. You do not have to worry about it too much. The server element can contain the Logger and ContextManager element types.
Logger
This element defines a Logger object. Each Logger is identified by a name. It also records the output and redundancy levels of Logger and the paths containing log files. generally, there is a servlet Logger (ServletContext. logger at log (), JSP and Tomcat runtime.
ContextManager
ContextManager describes the configuration and structure of a set of ContextInterceptor, RequestInterceptor, Context and their ORs ors. ContextManager has the following features:
1. the debugging level used to record debugging information
2. The basic locations of webapps/, conf/, logs/, and all defined environments are used to enable Tomcat to be started in other directories except TOMCAT_HOME.
3. working directory name
ContextInterceptor & RequestInterceptor
These listeners listen for events that occur in ContextManager. for example, ContextInterceptor listens for Tomcat startup and termination events, and RequestInterceptor monitors the different stages in which user requests need to pass during its service process. the Tomcat Administrator does not need to know much about the listener. In addition, developers should know how to implement a "global" Operation (such as security and each request log) in Tomcat)
Connector
Connector indicates a connection to the user, whether through a web server or directly to the user's browser (in an independent configuration ). connector is responsible for managing Tomcat worker threads and requests/responses connecting reading/writing to ports of different users. the Connector configuration includes the following information:
1. Handle class
2. TCP/IP Port of the handle listener
3. Handle the backlog of the TCP/IP of the server port.
We will describe how to configure ctor later in this document.
Context
Each Context provides a sub-directory pointing to Tomcat where you place your Web project. Each Context contains the following configurations:
1. The path where the Context is stored. It can be the path related to the ContextManager main directory.
2. Record the debugging level of debugging information
3. reload flag. during Servlet development, reload the changed Servlet. This is a very convenient feature. You can debug or use Tomcat to test new code without stopping or restarting Tomcat. to enable the reloadable function, set reloadable to true. this takes time but can detect changes. More importantly, the class loading trigger may throw some errors when a class object is loaded into a new servlet. to avoid these problems, you can set the reload to false, which will stop the reload function.
Start Tomcat from another directory
As the default value, atat_home/conf/server. xml is used as the configuration file. The default configuration uses TOMCT_HOME as the basis of the relational environment.
Use "-f/Your/directory/server. xml "option you can change this situation, you need to set the following files in the main directory to use another server configuration file and set the directory properties of the relational environment manager:
Ø A webapps/directory (if you have generated one)-all war file trophy circles overwhelm this directory and all subdirectories will be added as relational environments.
Ø conf/directory-you can save a special web. xml file and other configuration files.
Ø logs/-all log files will be recorded in this directory instead of atat_home/logs/
Ø work/-working directory of the relational environment
For example, the ContextManager. home attribute in server. xml is associated with the current working directory.
Web. Xml
About web. Detailed descriptions of xml and web project structures (including directory services and configurations) can be found in chapter 9, 10, and 14 of Servlet API Spec.
However, a small "feature" related to Tomcat is related to web. xml. Tomcat allows you. xml is put into the conf directory to define the web of all relational environments. xml default value. tomcat uses the default web. the xml file is used as the basic settings and application project-specific web. xml (WEB-INF/web in the application project. to overwrite these default values.
Set up Tomcat and Apache Web Servers
Server
So far, we have not discussed Tomcat as a server extension, but we have discussed it as a server that runs independently. However, there are some problems that need to be explained:
1. Tomcat is not as fast as Apache when processing static pages.
2. Tomcat is not configurable Like Apache.
3. Tomcat is not as strong as Apache.
4. Many websites have invested a long time on a specific web server, for example, using CGI scripts/Server API modules/perl/php... We cannot assume that all these legacy things will be discarded.
For the preceding reasons, we recommend that you use a Web server, such as Apache, to provide services for website static page requests and use Tomcat as a Servlet/JSP plug-in.
We are not going to discuss each configuration in depth. We will:
1. covering basic Web server Behaviors
2. Explain the configuration required
3. instances on Apache
Web server operations
Simply put, web servers always wait for HTTP requests from clients. When a request arrives, the server provides all necessary content to satisfy the request. Adding a Servlet container will change this behavior to some extent. However, the server still needs to handle the following factors:
Load the servlet container interface library and initialize it (before processing the request ).
When receiving a request, check whether it belongs to a Servlet. If so, the interface library receives the request and processes it.
On the other hand, the interface library needs to know that it will serve a certain request, usually a certain mode based on the request URL and where to direct this request.
When a user wants to configure and use a virtual host, things will become more complicated, or he wants multiple developers to develop on one server but use JVMs of different Servlet containers. We will discuss the two issues below.
Required Configuration
The most obvious configuration is that the servlet URL has the responsibility to represent the servlet in the servlet container. Obviously, you must know what to pass to the Servlet container. We still need to provide additional configuration items to the web-server or servlet-container combination.
L considering whether the Tomcat process can be obtained, we still need to provide the configuration and the TCP/IP host name/port number that Tomcat is listening.
L The location of the web server interface library needs to be informed (so we can import it at the beginning)
L you need to set the interface internal information, such as where and how to record logs.
All such information must appear in the web server configuration or the private configuration file used by the interface. The following describes how to implement these configurations in Apache.
Implementation on Apache
This section demonstrates how to configure Apache and Tomcat to work together, and tries to explain the configuration specifications that may be used in depth. Other information is available on the jserv installation page.