Tomcat4.01 Configuration Full Introduction

Source: Internet
Author: User
Tags contains http request implement interface join jboss access port number
Strategy
Related URL: http://www.yufeng.net
-----------------------------

Tomcat4.01 Full Raiders
One: Introduction
Tomcat is an important subproject in the Jakarta Project, selected by Javaworld Magazine as the most innovative Java product of the 2001 (Most innovative Java products), It is also the official web-recommended servlet and JSP container (see http://java.sun.com/products/jsp/tomcat/), so it is increasingly popular with software companies and developers. The latest specification for servlet and JSP can be implemented in a new version of Tomcat.

Second: Installation and configuration
The latest version of Tomcat is 4.0.1, which uses a new servlet container Catalina to fully implement the servlet2.3 and jsp1.2 specifications. Note that your system must have the jdk1.2 above installed before installation.

(i): Installation
1:windows Platform
By downloading Jakarta-tomcat-4.0.1.exe from the Tomcat site, you can install Tomcat with the usual Windows program installation steps, and it automatically looks for the location of your JDK and JRE when you install it.

2:linux Platform
Download the jakarta-tomcat-4.0.1.tar.gz and extract it into a directory.

(ii): Configuration
Running Tomcat requires setting the Java_home variable
Set JAVA_HOME=C:/JDK (Win98, used in msdos mode, or put into Autoexec.bat)
Export JAVA_HOME=/USR/LOCAL/JDK (used under Linux, put in/ETC/BASHRC or/etc/profile)

(iii): operation
After Setup, you can run the Tomcat server, enter Tomcat's Bin directory, start Tomcat with startup under Win98, Linux with startup.sh, the corresponding turn off Tomcat command for shutdown and shutdown.sh.
After startup, you can enter the http://localhost:8080/test in the browser, because Tomcat itself has the functionality of the Web server, so we do not have to install Apache, of course, it can also be integrated with Apache, described below.
Below you can test its own JSP and servlet samples.

Third: Application

(i): directory structure
The directory structure of Tomcat is as follows:
Directory Name: Introduction
Bin: Storing startup and shutdown Tomcat scripts
Conf: Contains different profiles, Server.xml (Tomcat's primary profile) and Web.xml
Work: Store the JSP generated class file after compiling
WebApp: Store application examples, and the applications you want to deploy will be placed in this directory
Logs: Storing log files
Lib/japser/common: These three directories primarily contain the jar files required by Tomcat


(ii): Introduction to Server.xml Configuration
Below we will cover the basic configuration information in this file, more specific configuration information see Tomcat's documentation
Server
PORT specifies the ports that are responsible for listening for requests to shut down Tomcat
SHUTDOWN Specifies the command string to be sent to the port
Service
Name to specify service names
Connector (indicates the connection between client and service):
PORT Specifies the port number to be created on the server side and listens for requests from the client on this fracture surface
Minprocessors number of threads created at server startup to process requests
Maxprocessors the maximum number of threads that can be created for processing requests
Enablelookups If True, you can obtain the actual hostname of the remote client by calling Request.getremotehost (), or false, and return its IP address instead of the DNS query
REDIRECTPORT specifies that the server is processing an HTTP request and receives a port number that is redirected after an SSL transfer request
ACCEPTCOUNT Specifies the number of requests that can be placed in the processing queue when all available processing requests are used, and requests that exceed this number will not be processed
ConnectionTimeout specify the number of times to timeout in milliseconds
Engine (represents a request processor in a specified service, receiving and processing requests from connector):
DEFAULTHOST Specifies the host name of the default processing request, which is at least the same as the Name property value of one of the host elements
Context (representing a Web application, usually a war file, and specific information about war, see servlet specification):
DocBase the path of the application or the path that the war file holds
Path represents the prefix of the URL for this Web application, so the URL for the request is http://localhost:8080/path/****
Reloadable This property is important, and if true, Tomcat automatically detects changes in the application's/web-inf/lib and/web-inf/classes directories, automatically loading new applications, We can change the application without having to restart Tomcat.
Host (represents a virtual host):
Name Specifies host name
AppBase Application Base directory, that is, the directory where the application resides
Unpackwars if True, Tomcat automatically extracts the war file, otherwise it does not understand the pressure and runs the application directly from the war file
Logger (for logs, debugging, and error messages):
CLASSNAME specifies the class name used by Logger, which must implement the Org.apache.catalina.Logger interface
prefix specifies the prefix of the log file
suffix specifies the suffix of the log file
Timestamp if true, the log file name is added to the time, as in the following example: Localhost_log.2001-10-04.txt
Realm (a database that holds user names, passwords, and role):
CLASSNAME specifies the class name used by realm, which must implement the Org.apache.catalina.Realm interface
Valve (features similar to logger, whose prefix and suffix properties are interpreted as in logger):
CLASSNAME specifies the class name used by valve, such as the use of Org.apache.catalina.valves.AccessLogValve classes to record access information for an application
directory specifies where log files are stored
Pattern has two values, common way to record the remote host name or IP address, username, date, the first line of the requested string, HTTP response code, the number of bytes sent. Combined is more than the common way to record

Attention:
1: After my test, I set the context of the Path= "", Reloadable=true, and then put a war file into the WebApps directory, the result Tomcat can not detect this file (restart Tomcat can), and the file decompression, Then Tomcat automatically detects the new application. If the war file cannot be automatically detected, we can deploy the application using the methods in the management below.

2: In the default server.xml, the realm element sets only one classname attribute, but this file also contains several examples of validation connected to the database through JDBC (commented out), and we can implement container security management through the realm element (Container Managed security).

3: There are some elements that we did not introduce, such as Parameter,loader, where you can get information about these elements through Tomcat's documentation.

(iii): Management

1: Configuration
Before we do any specific management, we add a user to Tomcat so that the user has permission to administer.
Open the Tomcat-users.xml file in the Conf directory and add the following line in the appropriate location:

<user name= "ZF" password= "ZF" roles= "Standard,manager"/>
Note: The last part of this line must be the/>,tomcat document dropped/symbol, and if no/symbol is available, Tomcat will not be able to access the application when it is reset. You can see the details of this error through the Logs/catalina.out file.

Then restart Tomcat, enter http://localhost:8080/manager/in the Browser, pop-up dialog box, enter the user name and password above.

2: Application list
When you enter http://localhost:8080/manager/list in the 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 above is the path to the application, the current state (running or stopped), and the number of sessions connected to the program.

3: Reloading the application
Enter Http://localhost:8080/manager/reload?path=/examples in the browser, and the browser displays the following:

ok-reloaded application at the context Path/examples

Indicates that the example application mount succeeded, and if we set the Reloadable property of the Server.xml context element to true (see table above), there is no need to reload the application this way because Tomcat automatically mounts.

4: Show Session information
Enter Http://localhost:8080/manager/sessions?path=/examples in the browser, and the browser displays the following:

Ok-session information for application in context Path/examples Default maximum session inactive interval

5: Start and close the application
Enter Http://localhost:8080/manager/start?path=/examples and http://localhost:8080/manager/stop?path=/in the browser Examples start and close the examples application separately.

6: Deploy and Undo Deployment
There are two ways to organize a war, one is to organize files by a certain directory structure, one is a compressed package with a suffix of war, so it is deployed in two ways:
(1): In the browser input: Http://localhost:8080/manager/install?path=/examples&war=file:/c:examples
The war deployment organized by directory structure

(2): if input: http://localhost:8080/manager/install?path=/examples&war=jar:file:/c:examples.war!/
The war deployment will be organized according to the compressed package, noting that the second half of this URL must have a!/number.
It can be accessed with http://localhost:8080/examples after deployment.

Enter in the browser: Http://localhost:8080/manager/remove?path=/examples will undo the application you just deployed.

(iv): with Apache integration
Although Tomcat can also be used as a Web server, its handling of static HTML is not as fast as Apache, and its function as a Web server is far less than Apache, so we want to integrate Apache and Tomcat.
Let's take a Linux system as an example.
Download the apache1.3.22 source code version from the Apache web site, and then configure Apache with 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 The Configure command specifies the target installation directory, and join the DSO (Dynamic Shared Object) support, and be sure not to forget this option.

Then download the WebApp module, will extract the mod_webapp.so file into the Apache libexec directory, edit Apache in the Conf directory of httpd.conf, in the end of this file to add the following three lines:

LoadModule Webapp_module libexec/mod_webapp.so
Webappconnection warpconnection Warp localhost:8008
Webappdeploy examples warpconnection/examples/

The first line is to join the WebApp module, if the compilation of Apache does not increase DSO support, you can not use the LoadModule directive, the second row specifies Tomcat and Apache connection, the third line specifies the deployment of the application, the two instructions use the following format:

Webappconnection [Connection Name] [provider] [Host:port]
Webappdeploy [application name] [connection name] [URL path]

Where connection name specifies the connection name, provider can only be the Warp,port port consistent with the last few lines of your Tomcat profile server.xml. The documents are as follows:

<service name= "Tomcat-apache" >
<connector classname= "Org.apache.catalina.connector.warp.WarpConnector"
Port= "8008" minprocessors= "5" maxprocessors= "75"
Enablelookups= "true"
Acceptcount= "Ten" debug= "0"/>
******
</Service>

Application name is consistent with the application name you deployed in Tomcat, and URL path specifies the URL to access the application. For example, the above example can be accessed through http://localhost/examples/to examples applications in Tomcat.

(v): Chinese question
The general JSP's garbled problem can be solved by adding <%@ page contenttype= "text/html;charset=gb2312"%> in the JSP, As for the garbled servlet, the httpserveletrequest.setcharacterencoding function provided in the servlet2.3 can be used. For more detailed Chinese questions, see the encoding problem in Jsp/servlet.

Four: summary
Tomcat as a servlet (JSP is also compiled as a servlet execution) container, its application prospects are very good, if combined with JBoss, you can implement the Sun Java EE specification (with JBoss as an EJB server). JBoss's official website also provides an integrated tomcat3.2* of JBoss for downloading. Another open source application server (Enhydra) is also based on Tomcat, which provides a more user-friendly management interface and is simpler and more powerful to deploy applications.

Win98
Configuration of environment variables by editing C:\autoexec.bat
Add to
Set java_home=c:\jdk1.4
Set catalina_home=c:\jatarta-tomcat-3
Set Classpath=c:\jatarta-tomcat-3\common\lib Ervlet.jar;
Set path=c:\windows; C:\jdk1.4\bin
may also need to increase your environment space, edit C;\config.sys
Increase
shell=c:\command.com/e:1024/p
You can start Windows again.



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.