Tomcat Raiders (transfer)

xiaoxiao2021-03-06  46

With the popularity of Java, its application on the Web is getting wider and wider, as an open source servlet container, the application prospect is getting wider, this article will tell you some of Tomcat.

One: Introduction

Tomcat is an important subproject in the Jakarta project, which is selected as the most innovative Java product in 2001 (Most Innovative) by the JavaWorld Magazine Editor

Java Product, at the same time, it is a SERVLET and JSP container recommended by Sun (you can see http://java.sun.com/products/jsp/tomcat/), so it is more and more software companies and Developers' love. The latest specifications for servlet and JSP can be implemented in the new version of Tomcat.

Two: Installation and configuration

The latest version of Tomcat is 4.0.1, which has a new servlet container Catalina, and fully implements servlet2.3 and jsp1.2 specification. Note that your system must have JDK1.2 or higher before installation.

(1): Installation

1: Windows platform

Download Jakarta-Tomcat-4.0.1.exe from the Tomcat website, follow the general Windows program installation steps to install Tomcat, which will automatically look for your JDK and JRE.

2: Linux platform

Download Jakarta-Tomcat-4.0.1.tar.gz, unzip it to a directory.

(2): configuration

Run Tomcat requires setting java_home variables

Set java_home = c: / jdk (Win98, use in MSDOS mode, or put in autoexec.bat)

Export java_home = / usr / local / jdk (Used under Linux, put it in / etc / bashrc or / etc / profile)

(3): operation

After the setting is completed, you can run the Tomcat server. Enter the bin directory of Tomcat, start Tomcat with Startup with Startup, linux with startup.sh, the corresponding shutdown Tomcat command is shutdown and shutdown.sh.

Enter http: // localhost: 8080 / test in the browser after startup, because the Tomcat itself has a web server function, so we don't have to install Apache, of course, it can also be integrated with Apache, which will be introduced below.

Below you can test their own JSP and servlet examples.

Three: Application

(1): directory structure

Tomcat's directory structure is as follows:

Directory name

Introduction

bin

Store startup and close Tomcat scripts

CONF

Contains different profiles, server.xml (main configuration files for Tomcat) and Web.xml

Work

Store the Class file generated after JSP compile

WebApp

Store application examples, after you have to deploy applications, you must put this directory.

logs

Store log files

LIB / JAPSER / COMMON

These three directory mainly store Tomcat's JAR files

(2): Server.xml configuration introduction

Below we will tell the basic configuration information in this file, more specific configuration information see Tomcat's documentation

Element name

Attributes

Explanation

Server

port

Specify a port, this port is responsible for monitoring the request to close Tomcat

Shutdown

Specify the command string sent to the port

Service

Name

Specify the name of the service

CONNECTOR

(Indicating the connection between the client and the service)

port

Specifies the port number to be created by the server side and listen to the request from the client in this fracture.

MINPROCESSORS server starts the number of threads created when the server is started

MaxProcessors

Maximum number of threads that can be created

Enablelookups

If true, you can get the actual host name of the remote client by calling request.getRemoteHost (). If DNS query is not performed, it returns its IP address.

Redirectport

Specifies that the server is processing the HTTP request to receive an SSL transmission request after a heavy-oriented port number

ACCEPTCOUNT

Specifies that when all the number of threads that can be used is used, you can put the number of requests in the process queue, and the request for exceeding this will not be processed.

ConnectionTIMEOUT

Specifies the time number of timeout (in milliseconds)

Engine

(Represents request processing machine, receiving, and processing requesting from Connector)

Defaulthost

Specifies the host name of the default processing request, which is the same as the Name property value of one of the Host elements.

Context

(Representing a web application, usually a WAR file, see the Servlet specification for the specific information of WAR)

Docbase

The path to the application or the path stored by the WAR file

Path

Indicates the prefix of the URL of this web application, so the requested URL is http: // localhost: 8080 / path / ****

RELOADABLE

This property is very important. If True, Tomcat will automatically detect changes in the application's / web-inf / lib and / web-inf / class directory, automatically load new applications, we can do not restart Tomcat Change the application

Host

(Representing a virtual host)

Name

Specify host name

APPBASE

Application Basic Directory, That is, the directory of the application

Unpackwars

If true, Tomcat will automatically decompress the WAR file, otherwise it is not extracted, running the application directly from the WAR file.

Logger

(Indicating log, debugging, and error message)

Classname

Specify the class name used by the Logger, this class must implement org.apache.catalina.logger interface

Prefix

Specifies the prefix of the log file

SUFFIX

Specifies the suffix of log files

Timestamp

If you are True, you should join the time in the log file name, as in the following example: localhost_log.2001-10-04.txt

Realm

(Indicating that the user name, password, and Role database)

Classname

Specify the class name used by Realm, this class must implement org.apache.catalina.Realm interface

Valve

(The function is similar to Logger, its Prefix and SUFFIX properties are the same as the Logger)

Classname

Specify the class name used by VALVE, such as using org.apache.catalina.valves.accessLogvalve class to record access information

Directory

Specify the location where the log file is stored

Pattern

There are two values, and the common host name or IP address, user name, date, first line requested string, HTTP response code, the number of bytes sent. Combined mode is more than the value recorded in the Common mode

Note: 1: After I tested, I set up PATH = "", reloadable = true, then put a WAR file to the webapps directory, and the tomcat can't detect this file (you can restart Tomcat), and decompress this file. The Tomcat will automatically detect this new application. If the WAR file cannot be automatically detected, we can use the methods described below to deploy applications. 2: In the default server.xml, the Realm element only sets a className property, but in this file, several examples connected via JDBC to the database (commented), we can implement container security through Realm elements. Container

Managed security).

3: There are still some elements. We have not introduced, such as parameter, loader, you can get information about these elements through Tomcat documents.

(3): management

1: Configuration

Before conducting specific management, we first add a user to Tomcat, so that this user has permission to manage.

Open the Tomcat-Users.xml file under the conf directory, add the following line in the appropriate location:

Note: The last part of this line must be />, Tomcat's document, if there is no / symbol, the Tomcat will not be able to access the application. You can see the details of this error by logs / catalina.out file.

Then recover Tomcat, enter http: // localhost: 8080 / manager /, will pop up in the browser, enter the username and password above.

2: Application list

Enter http: // localhost: 8080 / manager / list in your browser, the browser will display the following information:

OK - Listed Applications for Virtual Host Localhost

/ EX: RUNNING: 1

/ Examples: Running: 1

/ WebDAV: Running: 0

/ Tomcat-Docs: Running: 0

/ Manager: Running: 0

/: Running: 0

The information of the surface is the path of the application, the current state (running or stopped), which is connected to this program.

3: Re-load the app

Enter http: // localhost: 8080 / manager / relocalhost: 8080 / manager / relocalhost: 8080 / manager / repline? Path = / example, the browser is shown:

OK - Reloaded Application AT Context Path / Examples

Indicates that the Example application is loaded. If we set the reloadable property of Server.xml's Context element to True (see above), it is not necessary to reload the application using this manner because Tomcat will be loaded.

4: Show session information

Enter http: // localhost: 8080 / manager / sessions? Path = / examples, browser shown below in your browser:

OK - Session Information For Application At Context Path / Examples Default Maximum Session Inactive Interval 30 Minutes

5: Start and close the app

Enter http: // localhost: 8080 / manager / start? Path = / example: 8080 / manager / stop? Path = / examples, in your browser. 6: Deployment and revocation deployment

There are two ways to organize files in a certain directory structure, one is a compression package that suffixs for WAR, so it has two ways:

(1): Enter: http:// localhost: 8080 / manager / install? Path = / examples & war = file: / c: / example

WAR deployment will be organized according to the directory structure

(2): If you enter: http:// localhost: 8080 / manager / install? Path = / examples & war = jar: file: / c: /examples.war! /

The WAR deployed by the compression package will be deployed, note that the second half of this URL must have! / 号.

You can access by http: // localhost: 8080 / examples after deployment.

Enter: http: // localhost: 8080 / manager / remove? PATH = / Examples

The application that has just been deployed will be revoked.

(4) Integration with Apache

Although Tomcat can also make a web server, it processes static HTML than Apache, and its functionality as a web server is far less than Apache, so we want to integrate Apache and Tomcat.

We use the Linux system as an example.

Download the Apache 1.3.22 source version from the Apache website, then configure the installation of Apache using the following command:

MKDIR / USR / local / Apache

Tar zxvf apache.1.32.tar.gz

CD Apache.1.32

./configure --prefix = / usr / local / apache --enable-module = so

Make

Make Install

Note that the configure command sets the target installation directory and joins the DSO (Dynamic Shared Object) support, and be careful not to forget this option.

Then download the WebApp module, and put the mod_webapp.so file after decompression into the Libexec directory of Apache, edit the httpd.conf under Apache's confed, and add the following three lines in this file:

LoadModule WebApp_Module Libexec / Mod_Webapp.so

WebAppConnection WarpConnection Warp localhost: 8008

WebAppDeploy Examples WarpConnection / Examples / EXAMPLES /

The first line is to join the WebApp module. If you do not add DSO support when compiling Apache, you cannot use the loadModule instruction, the second line specifies the connection of Tomcat and Apache, and the third line specifies the application application. The two instructions use the format as follows:

WebAppConnection [Connection Name] [PROVIDER] [Host: Port]

WebAppDepLoy [Application Name] [Connection Name] [URL PATH]

Where Connection Name specifies the connection name, the Provider can only be WARP, the Port port is consistent with the last few lines of your Tomcat configuration file server.xml. The document is as follows:

Port = "8008" minprocessors = "5" MaxProcessors = "75" enablelookups = "true"

Acceptcount = "10" debug = "0" />

******

Application Name consistent with the app name you deployed in Tomcat, the URL PATH specifies the URL to access this application. For example, the above example can access the Examples app in Tomcat via http: // localhost / example.

(5): Chinese issues

General JSP garbled issues can be solved by adding in JSP, as for servlet's garbled in servlet2.3, the httpserveletRequest.SetCharacterenceEutReeNCoding function provided in Servlet 2.3. For more detailed Chinese issues, please see JSP / Servlet.

Chinese character encoding problem.

Four: Summary

Tomcat acts as a servlet (JSP is also compiled into a servlet) container, its application prospect is very good, if combined with JBOSS, you can implement Sun's J2EE specification (using JBoss as an EJB server). JBoss's official website also provides JBoss integrated Tomcat3.2 * for download. Another open source application server (ENHYDRA)

Also based on Tomcat, it provides a more friendly management interface, and the deployment application is also simpler, and the function is also more powerful.

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

New Post(0)