Tomcat Simplified Chinese version Manual

Source: Internet
Author: User
Source: www.qcsky.net)
Jakarta-Tomcat Simplified Chinese version User Guide Part 1

This document provides the following basic information about Tomcat:
Tomcat binary Installation
Main content of Tomcat-related scripts
Main content related to server. XML, main configuration file of Tomcat
Instructions on how to set tomcat to work with the host Web Server
How to Use tomcat to configure a real-world web site
We hope this document is sufficient for new users to start using tomcat. If you cannot find some content, please (in the following order)
Search for Tomcat FAQ
Search for the Tomcat package list
Issue a problem to the Tomcat user email list
If the answer to this question does not exist, we encourage you to put the answer to the question in the Tomcat FAQ or this document. If you have any comments or suggestions on this document, please send it to the Tomcat mail list.

Getting started
Tomcat is a servlet container with a JSP environment. The servlet container is a shell that allows you to manage and activate servlet runtime based on user behavior.
Servlet containers can be roughly divided into the following categories:

Independent Servlet Container
A part of the built-in web server refers to the use of Java-based Web servers. For example, the servlet container is a part of the javawebserver, and the independent servlet container is the default mode of Tomcat.
Most Web servers are not based on Java. Therefore, we can obtain the following two container modes.

Servlet container in process
Servlet containers are used as Web Server plug-ins and Java containers. the Web server plug-in opens a JVM (Java Virtual Machine) in the internal address space to allow the Java container to run internally. if there is a request to call servlet, the plug-in will get control of this request and pass it (using JNI) to the Java container. in-process containers are suitable for multi-threaded, single-process servers and provide good running speed, but the scalability is insufficient.

Servlet container outside Process
The servlet container runs outside the address space of the web server and acts as a web server plug-in and Java container implementation. the Web server plug-in and Java container JVM use the IPC Mechanism (usually TCP/IP) for communication. when a servlet call request arrives, the plug-in will get control over the request and pass it (using IPC, etc.) to the Java container, the response time of the non-process container or the out-process container engine is not as good as that of the In-process container, but the out-process container engine is better in many other comparable scopes (such as scalability and stability ).
Tomcat can be used as an independent container (mainly for development and debugging) and as an additional to the existing Server (currently Apache, IIS, and Netscape servers are supported ). that is, you must decide how to apply Tomcat at any time. If you select the second or third mode, you also need to install a web server interface.
What is the difference between Tomcat and jserv? Is Tomcat jserv?
This is a common misunderstanding. jserv is a container compatible with Servlet api2.0 and used with Apache. Tomcat is a fully rewritten container compatible with Servlet api2.2 and jsp1.1.
Tomcat uses some code written for jserv, especially the Apache interface of jserv, but this is the only difference.
How to install the binary version of Tomcat?
Very simple, just:
Download any zip/tar.gz compressed files from http://jakarta.apche.org/download/binindex.html.
Decompress the file to a directory (such as Foo). a subdirectory named "Tomcat" will be generated ".
Switch to the Tomcat directory and set a new environment variable (tomcat_home) pointing to the Tomcat directory you have installed.
For the Win32 platform, type:
"Set tomcat_home = Foo \ Tomcat"
UNIX platform:
In the bash/SH environment, type: "tomcat_home = Foo/tomcat; export tomcat_home"
If the tcsh environment is used, type: "setenv tomcat_home Foo/tomcat"
Set the environment variable java_home to point to your JDK directory, and then add the Java interpreter to your path environment variable.
Okay! Now you can run Tomcat and use it as an independent servlet container (mode 1)
Start and close Tomcat
Use the script in the "bin" directory to start and close tomcat.
Start:
Uup: Bin/startup. Sh
Win32: bin \ Startup
Close:
UNIX: Bin/shutdown. Sh
Win32: bin \ Shutdown
Tomcat directory structure
Suppose you have decompressed Tomcat and you have obtained the following directory structure:
Directory name -- Description
Bin
Including the start/Close script
Conf
Contains different configuration files,
Including server. XML (the main configuration file of Tomcat) and Web applications with different Tomcat configurations set the default value web. xml
Doc
Contains various Tomcat documents
Lib
Contains jar files used by Tomcat. Any files in this directory on the UNIX platform are added to Tomcat classpath.
Logs
Where Tomcat stores log files
SRC
Servletapi source file. Don't be happy, these are only some empty interfaces and abstract classes that must be implemented in the servlet container
Webapps
Contains web project examples
In addition, you can create the following directory for Tomcat:
Work
Automatically Generated by Tomcat and placed temporary files during Tomcat running (such as compiled JSP files). If you delete this directory during Tomcat running, the. jsp page cannot run.
Classes
You can create this directory to add some additional classes to the class path. Any classes you add to this directory can be found in the Tomcat class path.
Tomcat script
Tomcat is a Java program. Therefore, you can run it using the command line after setting several environment variables. however, setting each environment variable used by Tomcat and the following command line parameters is tedious and error-prone. therefore, the Tomcat Development Team provides some scripts to make it easy to start and close tomcat.
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, and so on, as long as a correct command line is generated.
What are these scripts? The following table lists the most important scripts for general users.
Tomcat
Main script. set appropriate environment variables, including classpath, tomcat_home and java_home, and start Tomcat with appropriate command line parameters

Startup

How to replace the tomcat. "Tomcat start" command in the background

Shutdown

How to replace the tomcat. "Tomcat stop" command

The most important script for users is Tomcat (tomcat. BAT/tomcat. SH ). other tomcat-related scripts serve as a simple entry to point to the Tomcat script (set different command line parameters, etc.) for a single task.

Take a closer look at tomcat. BAT/tomcat. Sh, which runs in the following steps:

Steps in UNIX:

If not specified, it is assumed that tomcat_home

If this parameter is not specified, it is assumed that java_home

Set class_path to include:

1. $ {tomcat_home}/classes directory (if any)

2. $ {tomcat_home}/lib

3. $ {java_home}/lib/tools. Jar (this jar file contains the javac tool. We need javac to process JSP files.

Run the Java command with the command line parameters for setting Java environment variables and call tomcat. home, and org. apache. tomcat. startup. tomcat serves as the startup class. the command line parameters are also passed to Org. apache. tomcat. startup. tomcat, for example:

Execute start/stop/run

The Tomcat process uses the path pointing to server. xml,

For example, if server. XML is placed in ETC/server_1.xml and you intend 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 Tomcat. bat of Win32 version is almost the same as that of UNIX version, especially when it does not speculate the value of tomcat_home and java_home, and does not put all jar files into the class path.

Tomcat configuration file

Tomcat configuration is based on two configuration files:

1. Global configuration file of server. XML-Tomcat

2. Web. XML-configure different relational environments in Tomcat

This section describes how to use these files. we do not include web. XML internal mechanisms, which go deep into the details of servlet APIs. Therefore, we will discuss servler. XML content and web. the usage of XML in the Tomcat relationship environment.

Server. xml

Server. XML is the main configuration file of Tomcat:

1. Provide the initial configuration of Tomcat components.

2. Describe the structure and meaning of Tomcat so that Tomcat can start and build itself by instantiating components, as specified in server. xml

The following table describes important elements of server. xml:

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.