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 Configuring a Realistic Web site I hope this document is enough to start using Tomcat. If you can't find someone, please find the Tomcat FAQ Find Tomcat Pack Refine Tomcat User Mail List Such questions do not exist, we encourage the solution to questions to Tomcat FAQ or this document. If you have any comments or suggestions for this document, please send it to Tomcat's mailing list. Getting StartedTomcat is a servlet container with JSP environments. The .servlet container is a shell that manages and activates the servlet's run according to the user's behavior. Roughly can divide the servlet container into a few categories: Separate servlet containers have part of the web server. Refer to use Java-based Web The server's case, such as the servlet container is a part of JavaWeb Server. Separate 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. SERVLET container The Servlet container is a web server's plugin and the implementation of the Java container .Web server plug-in opens a JVM (Java Virtual Machine) to make Java containers internally. If a request to call servlet, the plugin will get Control of this request and deliver him (using JNI) to the Java container. Process Content For multi-threaded, single-process server is very suitable and provides a good running speed, but the scalability is insufficient. Servlet container outside the process The servlet container is running the address space other than the web server and the combination of the web server's plug-in and the implementation of the Java container .Web server plugin, and Java container JVM use IPC mechanisms (usually TCP / IP) to communicate. When a call servlet When the request arrives, the plugin will acquire the control of this request and deliver it (using IPC, etc.) to the Java container, the process export container, or the process outer container engine is not as good as the process, but the process outer container engine is in many other comparable Better (scalability, stability, etc.) in the range. Tomcat can be used as a separate container (mainly for development and commissioning) and can be used as an additional server (current support APAC) HE, IIS and Netscape servers). That is, you must decide how to 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 compatible with the servlet API 2.0 compatible with Apache. Tomcat is a completely rewritten and container compatible with Servlet API2.2 and JSP1.1. Tomcat uses some JSERV The code, especially the Apache interface of JSERV, but this is the only thing. How to install Tomcat's binary version? Very simple, just: download zip / tar.gz any compressed file, from http: // jakarta .apche order.org / download / binindex.html. Unzip this file to a directory (such as: foo). The one son directory will be generated, named "Tomcat". Convert to "Tomcat" directory Setting up a new environment variable (Tomcat_home) Points to the Tomcat of Tomcat, 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 Check Move and terminate events, Requestinterceptor monitors different stages of the user requests to pass during its service process. Tomcat does not have to know too much about the listener; in addition, developers should know how this is "one" 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, using another server profile and setting relational environment manager's directory property you need to set the following files in the main directory: Ø A webApps / directory (if you have generated) - All WAR file trophy 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 profile Ø logs / - all log files will replace Tomcat_Home / Logs / Record 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.