Jakarta-simple Chinese version of Tomcat User Guide

Source: Internet
Author: User

(This article comes from http://web.domaindlx.com/cyberz/ctomcat1.htm)

 

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 omcat"


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: binstartup

Close:

Unix: bin/shutdown. sh

Win32: binshutdown


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 the web server or directly to

Related Article

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.