Tomcat Chinese Manual
This document provides basic information about Tomcat. The main contents are as follows: Tomcat binary version installation with the main content of Tomcat related scripts related to server.xml, Tomcat's main configuration file How to set up Tomcat and host web server How to apply Tomcat to configure a realistic Web site
I hope this document is enough to enable new users to start using Tomcat. If you can't find someone, you can find Tomcat FAQ Find Tomcat Packs Qing one-way Tomcat user mailing list issues a question of such question does not exist, we encourage Add questions to the Tomcat FAQ or this document. If you have any comments or suggestions for this document, send it to Tomcat mailing list. Getting StartedTomcat is a servlet container with a JSP environment. Servlet container is a user's behavior Manage and activate the run of the servlet. Roughly can divide the servlet container into a few categories: Separate servlet containers have part of the web server. Refers to the case of using Java-based web servers, such as servlet containers are JavaWeb Server A section. Independent servlet container is the default mode of Tomcat. Most web servers are not based on Java, so we can draw the models of the following two containers. The servlet container servlet container as a web server and Java container Implementation .Web server plug-in opens a JVM (Java Virtual Machine) to make Java containers in internal address space to run internal. If a request to call servlet, the plugin will get the control of this request and pass him ( Use JNI to give Java containers. Procesers are very suitable for multithreading, single-process server is very suitable and provide a good running speed, but the scalability is insufficient. The servlet container servlet container runs outside the web server. The space and the combination of the web server's plug-in and the Java container .Web server plugin, and Java container JVM use IPC mechanisms (usually TCP / IP) to communicate. When a request to a call servlet arrives, the plugin will obtain the request. Control and transfer (using IPC, etc.) to the Java container, the reaction time or process outer container engine of the process outer container is not as good as the process, but the process outer container engine is better (scalability, stable) within many other comparable ranges. Sexuality) .tomcat can be used as a separate container (mainly for development and commissioning), which can be used as an additional server (currently supporting Apache, IIS, and Netscape servers). That is to configure Tomcat, you must decide Apply him, if you choose the second or third mode, you still need to install a web server interface. What is the difference between Tomcat and JSERV? Tomcat is JSERV? This is a common misunderstanding .jserv is Servlet API2.0 compatible with The container used together. Tomcat is a fully rewritten and container compatible with Servlet API2.2 and JSP1.1. Tomcat uses some code written by JSERV, especially Jserv's Apache interface, but this is unique The same. How to install Tomcat's binary version? Very simple, just: download zip / tar.gz any compressed file, from http://jakarta.apche.Org/download/binIndex.html. Unzip this file to A directory (such as: foo) will generate a subdirectory, named "Tomcat". Convert to "Tomcat" directory Setting up a new environment variable (Tomcat_home) point to the Tomcat of Tomcat Win32 platform, type: "SET Tomcat_home = foo / tomcat "UNIX platform: If it is a Bash / SH environment, type:" Tomcat_home = foo / tomcat;
Export Tomcat_Home "If the TCSH environment, type:" setenv tomcat_home foo / tomcat "Set the environment variable java_home points to your JDK directory, then add the Java interpreter to your PATH environment variable. Ok! Now you can run Tomcat and as an independent Servlet Container (Mode 1) Starts with Close Tomcat Using Scripts in the "bin" directory launch and close Tomcat. Start: uinx: bin / startup.shwin32: bin / startup close: UNIX: bin / shutdown.shwin32: bin / shutdowntomcat directory Structure Hypothesis You have decompressed Tomcat, you have got the following directory structure: Directory Name - Description BIN contains Start / Close script Conf contains different profiles, including server.xml (Tomcat's primary configuration file) and for different Tomcat configurations Web Application Settings Defaults File Web.xmldoc Contains Various Tomcat Document Lib Contains Tomcat JAR Files. UNIX Platform Any files in this directory are added to Tomcat's ClassPath Logs Tomcat placed in Logs Tomcat placed in Logs Tomcat ServletAPI source files. Don't happy, these only some of the air interfaces and abstract class WebAPPs that must be implemented in the servlet container contains web project examples. Some you can create the following directory: Worktomcat automatically generates, place Tomcat Timatics (such as Compiled JSP files). If you delete this directory when you run. Thejsp page will not be able to run. Classes You can create this directory to add some additional categories to classpaths. Anything you add this directory can be Finding itself in Tomcat's class path Tomcat is a Java program, so you can run how to use the command line after setting several environment variables. However, set each environment variable used by Tomcat and the following command line parameters. And error. Therefore, Tomcat development group provides some scripts to make the startup and closing Tomcat easier. Note: These scripts are just a convenient way to start and close Tomcat. You can modify them to customize ClassPath, environment variables such as Path, LD_LIBRARY_PATH,, etc., as long as it produces a correct command line. What is these scripts? The following table lists the most important scripts for the general user. Tomcat main script. Set the appropriate environment variable, including ClassPath, Tomcat_Home and JAV A_HOME and use the appropriate command line parameter Start Tomcat Startup Start Tomcat in the background. The replacement of the Tomcat Start command Shutdown Close Tomcat. The Tomcat Stop command has a replacement method of the user's most important script is Tomcat (Tomcat.bat / Tomcat .sh). Other Tomcat-related scripts as a simple point-oriented Tomcat script (set different command line parameters, etc.). Carefully examine tomcat.bat / tomcat.sh, follows: in UNIX The step of the next step: If it is not specified, it is specified that tomcat_home is not specified, speculating java_home setting class_path contains: 1. $ {Tomcat_home} / classes directory (if present) 2. $ {Tomcat_home} / lib 3. $ {Java_home} /LIB/Tools.jar (This JAR file contains tool javac, we need JAVAC to handle the JSP file. Run the java command with the command line parameters with the setting Java environment variable, tall tomcat.home, and org.apache.tomcat. Startup.tomcat is started. At the same time, the command line parameter is also passed to org.apache.tomcat.Startup.tomcat, such as operation of start / stop / run, etc. This Tomcat process uses the path to Server.xml, such as Server. XML is placed in ETC / Server_1.xml and the user is intended to start apache in the background, type the following command line: bin / tomcat.sh start -f /etc/server_1.xml Steps under Win32:
(Omitted) It can be seen that the Win32 version of Tomcat.Bat is almost consistent with UNIX version. Especially in it does not speculate Tomcat_Home and Java_home value, and do not put all JAR files into the class path. Tomcat configuration file Tomcat Configuring two profiles: 1.Server.xml - Tomcat global configuration file 2.Web.xml - Configuring different relationships in Tomcat This section will tell how these files will contain these files. We will not contain Web.xml interior Mechanism, these internal mechanisms go deep into the details of the Servlet API, so we will discuss the usage of servler.xml content and web.xml in the Tomcat relational environment .Server.xmlserver.xml is the main configuration file of Tomcat. Complete two goals 1 provides the initial configuration of Tomcat components. 2 Description Tomcat structure, meaning, so that Tomcat completes the start and build itself by instantiation components, such as the following table specified in Server.xml Important elements: Elements and It describes the most important elements in the ServerServer.xml file. Server defines a Tomcat server. You don't have to worry too much. Server elements can contain logger and contextManager type Logger this element defines a logger object, each logger has A name demonstrates, there is also a record logger's output and redundancy level (describes this log level) and the path to the log file. There is usually a logger (servletContext.log (), JSP and Tomcat running Logger. ContextManagerContextManager Description A set of ContextInterceptor, RequestInterceptor, Context, and their Connectors configuration and structure. ContextManager has several features available: 1. Debug debugging levels 2. WebApps /, conf /, logs / and all have The basic location of the defined environment is used to make Tomcat can start in other directories outside Tomcat_HOME. 3. Working directory Name ContextInterceptor & RequestintercePtor These listeners These listeners These listeners These listeners These listeners These listeners These listeners are listened to events that occur in ContextManager. For example, Contextinterceptor listens Tomcat of Start and terminating events, requestInterceptor monitors different stages of the user requests to pass during its service process. Tomcat's administrator does not have to know too much about listener; in addition, developers should know how this is in Tomcat " Global "operation (such as security and each request log) ConnectorConnector represents a user's join, whether it is through the web server or directly to the user browser (in a stand-alone configuration) .connector is responsible for managing Tomcat's working thread and Request / Response of the port connected to different users. The configuration of the Connector contains the following information: 1. Handle 2. Handle 6 Handle Survey TCP / IP Port 3. The TCP / IP of the handle server port. We will In this document, describe how to configure Connector.Context Each context provides a subscriber directory that pointing to Tomcat of your web project.
Each context contains the following path, which is placed, can be the path associated with the ContextManager home directory. 2. Record debugging information debug level 3. Overloaded flag. When developing servlet, overload the rear SERVLET This is a very convenient feature that you can debug or use Tomcat to test the new code without stopping or restart Tomcat. To open the overload, set the reloadable to true. This takes time but detects changes More important things, in view of a new servlet when a mountable object is loaded, the class load trigger may throw some errors. To avoid these issues, you can set overloaded as a false, which will stop heavy Load function. Starting Tomcat from another directory as the default value will use Tomcat_home / conf / server.xml as a configuration file. The default configuration will use tomct_home as the basis of the relational environment. Use "-f / your / directory / server .xml option You can change this situation, using another server profile and setting relational environment Manager's directory properties you need to set the following files in the home directory:? A webApps / directory (if you have generated) - All WAR file trophies overwhelves this directory and all subdirectories will be added as a relational environment.? Conf / directory - You can save a special web.xml file and other profiles? Logs / - All log files will replace Tomcat_Home / Logs / Records to this directory? Work / - Relational environment work directory such as the ContextManager.home attribute in Server.xml is associated, will associate to the current work directory .web. XML about the web. A detailed description of the XML and Web project structures (including directory services and configurations) can be found in Chapters 9, 10, 14 of Servlet API SPEC. However, there is a small "characteristic" related to Tomcat. Tomcat allows users to define the default value of all the Web.xml of all relationship environments by putting the default web.xml into the confed directory. When establishing a new relationship environment, Tomcat uses the default web.xml file as the basics. Set and apply item-specific web.xml (web-inf / web.xml files for application items) to override these defaults. Set Tomcat and Apache Web Server Servers until now, we have not discussed Tomcat as servers Only a server that is running independently. However, there are some problems to explain: 1. Tomcat is not as fast as Apache when it is handled in the static page. 2. Tomcat is not as strong as Apache. 4 There are many websites that have been put in a particular Web Server for a long time, for example, using CGI scripts / server API modules / perl / php ... We can't assume that things left will be discarded. Based on the reasons, one Realistic website recommends using a web server, such as Apache, providing services for the static page of the website, and use Tomcat as a servlet / jsp plugin. We are not prepared to discuss each different configuration, we will: 1. Cover Web Server Basic Behavior 2. Explain what configuration requires 3. Example web server operation on Apache is simply, the web server is always waiting for HTTP requests from the client. When the request arrives, the server will provide everything necessary to meet this request. Add a servlet container to some extent change this behavior. But the server still needs to process the following factors: load the servlet container interface library and initialize (before processing the request). When a request is received, check if it belongs to a servlet, if so, the interface library receives this request and processes. On the other hand, the interface library needs to know that he will serve some request, usually a mode based on the request, and where to guide this request. When the user wants to set the configuration using the virtual host, things become more complicated, or want multiple developers to develop JVMs for developing but use different servlet containers. We will discuss these two issues. The necessary configuration should consider the most obvious configuration is that the servlet URL has a representation of servlet in the servlet container.
Obviously, you must know what to pass on the servlet container. We still need to provide additional configuration items to the combination of web-server or servlet-container. LL considers whether the Tomcat process can be obtained, we still need to provide the TCP / IP hostname / port number of configuration and Tomcat is listening. l You need to inform the web server interface library (so we can load in the start-up time) l Supply internal information such as where to record logs and how to record, and so on. All such information must appear in a Web server configuration or in a private configuration file used by the interface. Here's how to implement these configurations in Apache. This part of the implementation on Apache demonstrates how to configure Apache to work with Tomcat; and try to explain the configuration specification that may be used in depth. Other information can be found on the JSERV installation page.