Basic information of Tomcat

xiaoxiao2021-03-06  110

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, find the Tomcat FAQ Find Tomcat Pack Listing to Tomcat User Mail list Such questions do not exist, we encourage the answer 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 Started Tomcat is a servlet with a JSP environment Container .Servlet container is a shell that can manage and activate servlet according to user behavior. Roughly can divide the servlet container into a few categories: Separate servlet containers have part of the web server. Refers to Java-based The WEB server, for example, 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 The container servlet container is a web server's plug-in 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, plugin will Get the control of this request and deliver him (using JNI) to the Java container. Processor Content For multi-threaded, the server is very suitable and provides a good running speed, but the scalability is insufficient. Servlet The container servlet container runs outside 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 outer container is not as good as the process instrument, but the process outer container engine is in many others. Comparison is better (scalability, stability, etc.). Tomcat can be used as a separate container (mainly for development and commissioning) It can also be used as an additional to existing servers (currently supporting Apache, IIS, and Netscape Servers). That is, you must decide how to apply him, such as selecting the second or third mode, you also 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 with Apache .tomcat is a completely rewritten and servlet API2.2 and JSP1 .1 compatible container. Tomcat uses some code written for JSERV, especially Jserv's Apache interface, but this is the same thing. How to install Tomcat's binary version? Very simple, just: Download Zip / Tar Any compressed file, from http://jakarta.apche.org/download/binindex.html. Unzip this file to a directory (such as: foo). A subdirectory will be generated, named "Tomcat". Convert to "Tomcat" directory Set a new environment variable (Tomcat_home) point 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) Start and close Tomcat Using Scripts in the "bin" directory launch and close Tomcat. Start: uinx: bin / startup.sh win32: bin / startup Off: UNIX: bin / shutdown.sh Win32: bin / The shutdown tomcat directory structure is assumed that you have decompressed Tomcat, you have got the following directory structure: Directory Name - Description BIN contains start / close script confes, including different profiles, including Server.xml (Tomcat's primary configuration file) and Tomcat Configuration Web Application Settings Defaults Web.xml DOC Contains Various Tomcat Document LIBs containing Tomcat JAR files. UNIX Platform Any files in this directory are added to Tomcat's classpath. Logs Tomcat placed logs File where SRC servletapi source files. Don't happy, only some of the voids and abstract class WebAPPs that must be implemented in the servlet container include web project examples. In addition, you can create the following directory: Work Tomcat automatically generates, place Tomcat runtime Temporary documents (such as compiled JSP files). If you delete this directory when you run. The JSP page will not be run. Classes You can create this directory to add some additional classes to class paths. Any you add this directory The class can find itself in the Tomcat's class path. Tomcat's script Tomcat is a Java program, so it can be run in the way you use the command line after setting several environment variables. However, set each environment variable used in Tomcat and the following The command line parameters are bored and error-wrong. Therefore, Tomcat development group provides some scripts to make the startup and close Tomcat easy. 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 more, 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 variables, packages Including ClassPath, Tomcat_Home and Java_Home and start Tomcat Startup with the appropriate command line parameters Start Tomcat in the background. The replacement of the Tomcat Start command Shutdown Close Tomcat. "Tomcat Stop" alternative to the user's most important script is Tomcat ( Tomcat.bat / tomcat.sh). Other Tomcat-related scripts as a simple point-oriented Tomcat script (setting different command line arguments, etc.). Carefully examine tomcat.bat / tomcat.sh, it follows Steps to run: Steps under UNIX:

As 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 / Tools .jar (This JAR file contains tool javac, we need JAVAC to handle JSP files. Run the java command with command line parameters with setting Java environment variables, tune tomcat.home, and org.apache.tomcat.startup.tomcat as Start the class. Also passes the command line parameter to org.apache.tomcat.startup.tomcat, for example: Operation of START / STOP / RUN This Tomcat process uses the path to Server.xml, such as server.xml placed in ETC /server_1.xml and the user is intended to start Apache in the background, the key is as follows: bin / tomcat.sh start? f /etc/server_1.xml Steps under Win32: () It can be seen, Win32 version of Tomcat. BAT is almost consistent with UNIX version. Especially in it does not speculate the value of Tomcat_Home and Java_Home, and do not place all JAR files into the class path. Tomcat's configuration file Tomcat is based on two profiles: 1.Server.xml - Tomcat Global Profile 2.Web.xml - This section configures different relationship environments in Tomcat how to use these files. We will not include the internal mechanism of Web.xml, these internal mechanisms go deep into the details of the servlet API, Therefore, we will discuss the usage of servler.xml content and web.xml in the Tomcat relationship environment. Server.xml server.xml is the primary configuration file of Tomcat. Complete two goals: 1 Provide 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 above table described in Server.xml: Elements and Its Description Server.xml files are the most important Elements. Server defines a Tomcat server. Generally, you don't have to worry too much. Server elements can contain Logger and ContextManager elements. Type Logger This element defines a logger object, each logger has a name to logo, and there is also a record Logger output and redundancy level (describe this log level) and a path to log files. Usually there is a servlets logger (servletContext. Logger, JSP, and Tomcat running logger. ContextManager ContextManager Description A set of ContextInterceptor, Requestinterceptor, Context, and their Connectors configuration and structure. ContenxtManager has several features: 1. Used to record debugging information Debug Level 2. WebAPPS /, CONF /, LOGS / and all the basic locations of all defined environments. To make Tomcat can start in other directories outside Tomcat_home. 3. Work directory The name of the CopyintercePtor & RequestinterCeptor These listeners (Interceptors) Listening to events in ContextManager. For example, Contextinterceptor listens to Tomcat's launch and termination event, Requestinterceptor monitors different stages of the user requesting to pass during its service process, do not have to know too much about listener ;

In addition, developers should know how this is how to implement a "global" operation in Tomcat (such as security and each request log) Connector Connector represents a connection to the user, 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 a request / response to ports to different users. The configuration contains the following information: 1. Handle 2. Handle 6 Handle TCP / IP port 3. The TCP / IP of the handle server port. We will describe how to configure Connector. Connext each context provides a subordinate directory to Tomcat, which you place your Web project. Each context contains the following configuration: 1. The path placed with the ContextManager main directory. 2. Record debugging information debug level 3. Overloaded flag. When developing servlets, 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 setup relationship property, you need to set the following files in the home 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 property 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 the server as an independent run. But there are some problems to explain: 1. When processed the static page, Tomcat is not as fast as Apache. 2. Tomcat is not as configured as Apache. 3. 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, serving a service for the site's static page request, 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.

转载请注明原文地址:https://www.9cbs.com/read-124327.html

New Post(0)