Tomcat Full Guide

Source: Internet
Author: User
Tags add time jboss

Content:
A: Brief introduction
II: Installation and Configuration
Three: Application
Four: Overview
References
About the author

Zong Feng
Master of Computer Science, Northwestern University
December 2001

with the popularity of Java, its application on the web is also more and more extensive, tomcat as an open-source servlet container, application prospects are more and more extensive, this article will tell you some of the knowledge of Tomcat.

A: Brief introduction
Tomcat is an important subproject in the Jakarta project, which was selected by editors of Javaworld Magazine as the most innovative Java product of the 2001 (Most innovative Java products). At the same time it is the official recommendation of Sun company servlet and JSP container (in detail to see http://java.sun.com/products/jsp/tomcat/), so it is more and more popular with software companies and developers. The latest specifications for Servlets and JSPs can be implemented in the new version number of Tomcat.

II: Installation and Configuration
The latest version of Tomcat is 4.0.1, this version number uses a new servlet container Catalina, which implements the servlet2.3 and jsp1.2 specifications completely. Note Before installing your system, you must install the jdk1.2 above version number.

(i): Installation
1:windows Platform
To download Jakarta-tomcat-4.0.1.exefrom the Tomcat site, you can install Tomcat in accordance with the usual Windows program installation steps, and it will proactively look for the location of your JDK and JRE at the time of installation.

2:linux Platform
Download the jakarta-tomcat-4.0.1.tar.gzand unzip it to a folder.

(ii): Configuration
Executing tomcat requires setting the Java_home variable

set JAVA_HOME=c:/jdk (win98,在msdos方式下使用,或者放入autoexec.bat中)export JAVA_HOME=/usr/local/jdk (linux下使用,放到/etc/bashrc或者/etc/profile中)


(iii): implementation
After the setup is complete, you can execute Tomcatserver, enter the Tomcat Bin folder, start Tomcat with startup under Win98, Linux with startup.sh, corresponding to the command to close Tomcat for shutdown and shutdown.sh.

You can enter http://localhost:8080/test in the browser after launch, because Tomcat itself has webserver functionality, so we don't have to install Apache, and of course it can be integrated with Apache, as described below.

Below you can test their own JSP and servlet demo sample.

Three: Application

(a): folder structure
The folder structure for Tomcat is as follows:

Folder name Simple Introduction
Bin Store startup and shutdown Tomcat scripts
Conf Includes different configuration files, Server.xml (Tomcat's primary profile) and Web. xml
Work Store the class file generated by the JSP compilation
WebApp Store the Application Demo sample, and the application you want to deploy in the future will also be placed in this folder
Logs Storing log files
Lib/japser/common These three folders primarily store the jar files required by Tomcat


(b): Server.xml Configuration Simple Introduction
Below we will tell you the basic configuration information in this file, and more detailed configuration information in the Tomcat documentation.

Element name Property Explain
Server Port Specify a port that is responsible for monitoring the request to close Tomcat
Shutdown Specify a command string to send to port
Service Name Specify the name of the service
Connector
(indicates a connection between client and service)
Port Specify the port number to be created by the server side and listen for requests from the client at this fracture
Minprocessors The number of threads that were created at server startup to process requests
Maxprocessors Maximum number of threads that can be created to process requests
Enablelookups If true, the actual hostname of the remote client can be obtained by calling Request.getremotehost (), and if False, the DNS query is returned instead of the IP address
Redirectport Specifies the port number that is redirected after an SSL transfer request is received by the server while it is processing an HTTP request
Acceptcount Specifies the number of requests that can be placed in the processing queue when the number of threads that can be used for processing requests is used, and requests that exceed this number will not be processed
ConnectionTimeout Specify the number of times to time out (in milliseconds)
Engine
(indicates the request processor in the specified service, receiving and processing requests from connector)
Defaulthost Specifies the default host name for processing requests, which is at least the same as the Name property value of one of the host elements
Context
(Represents a Web application, usually a war file, see the servlet specification for more information about the war)
DocBase The path to the application or the path where the war file is stored
Path Represents the prefix of the URL for this Web application, so the requested URL is http://localhost:8080/path/****
Reloadable This attribute is important, assuming true, then Tomcat will proactively detect changes in the application's/web-inf/lib and/web-inf/classes folders, proactively load new applications, and we can change the application without having to restart Tomcat

Host
(represents a virtual host)

Name Specify host Name
AppBase Application base folder, which is the directory where the application is stored
Unpackwars If true, Tomcat will proactively extract the war file, otherwise do not decompress and execute the application directly from the war file.

Logger
(indicates log, debug and error messages)

ClassName Specifies the class name used by Logger, which must implement the Org.apache.catalina.Logger interface
Prefix Specify a prefix for the log file
Suffix Specify the suffix of the log file
Timestamp If true, add time to the log file name, such as the following example: Localhost_log.2001-10-04.txt

Realm
(indicates the database hosting Username,password and role)

ClassName Specifies the class name used by realm, and this class must implement the Org.apache.catalina.Realm interface

Valve
(functions are almost identical to logger, and their prefix and suffix attribute interpretations are the same as in logger)

ClassName

Specify the class name that Valve uses, such as using the Org.apache.catalina.valves.AccessLogValve class to record the application's access information

Directory Specify where log files are stored
Pattern There are two values, the common method records the remote host name or IP address, the username, the date, the first line of the requested string, the HTTP response code, and the number of bytes sent. Combined way more than common way record value many other

Note: 1: After I test, I set the context of the Path= "", Reloadable=true, and then put a war file into the WebApps folder, the result Tomcat can not detect this file (restart Tomcat can), and the file decompression, Then Tomcat will proactively detect the new application. Assuming you cannot proactively test the war file, we are able to deploy the application using the following management methods.

2: The realm element only sets a classname attribute in the default server.xml, but this file also includes several demo samples that are validated by JDBC connection to the database (peered out), and we are able to implement container security management through the realm element ( Container Managed Security).

3: Other elements we did not introduce, such as Parameter,loader, you can get information about these elements through the Tomcat documentation.

(iii): Management

1: Configuration
Before we manage it in detail, we'll first add a user to Tomcat so that the user has permission to manage it.

Open the Tomcat-users.xml file under the Conf folder and add the following line to the corresponding location:


      
               


Note: The last part of this line must be the/>,tomcat document drop/symbol, assuming no/symbol, Tomcat will not be able to access the application when it restarts. You can see the specific information for this error through the Logs/catalina.out file.

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

2: Application list
To enter Http://localhost:8080/manager/list in the browser, the browser will display a sample of the following information, such as:

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 for the polygon is the path to the application, the current state (running or stopped), and the number of sessions connected to the program.

3: Loading the application again
Enter Http://localhost:8080/manager/reload?path=/examples in the browser, the browser shows a demo sample such as the following:

OK - Reloaded application at context path /examples  


Indicates that the example application was loaded successfully, assuming that we set the Reloadable property of the Server.xml's context element to true (see table above), it is not necessary to load the application again in such a way that Tomcat will mount it on its own initiative.

4: Show Session information
Enter Http://localhost:8080/manager/sessions?path=/examples in the browser, the browser shows a demo sample such as the following:

OK - Session information for application at context path /examples Default maximum session inactive interval 30 minutes  


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 REVOKE deployment
There are two ways to organize a war, one is to organize files according to a certain folder structure, one is a compressed package with the suffix war, so it can be deployed in two ways:
(1): In the browser, enter:http://localhost:8080/manager/install?path=/examples&war=file:/c:/examples
Will deploy the war organized by folder structure

(2): Assume input:http://localhost:8080/manager/install?path=/examples&war=jar:file:/c:/examples.war!/
The war that is organized by the compressed package will be deployed, and note that the second half of this URL must have a!/number.

Once deployed, you'll be able to access it with Http://localhost:8080/examples.

In the browser, enter:http://localhost:8080/manager/remove?path=/examples
The application you just deployed will be revoked.

(iv): integration with Apache
Although Tomcat can also be webserver, it does not handle static HTML as much as Apache does, and its function as webserver is far inferior to Apache, so we want to integrate Apache with Tomcat.

Let's take a Linux system as an example.

Download the apache1.3.22 source version number from the Apache site, and then use the following command to configure Apache for installation:

mkdir /usr/local/apachetar zxvf apache.1.32.tar.gzcd apache.1.32./configure --prefix=/usr/local/apache --enable-module=so makemake install


Note The Configure command specifies the target installation folder and adds the DSO (Dynamic Shared Object) support, so be sure not to forget this option.

Then download the webapp module , add the extracted mod_webapp.so file into the Apache Libexec folder, edit the httpd.conf under Apache Conf folder, add the following three lines at the end of this file:



The first line is to add the WebApp module, assuming that when compiling Apache does not add DSO support, you cannot use the LoadModule directive, the second line specifies the connection between Tomcat and Apache, the third line specifies the deployment of the application, the two instructions using the format such as the following:

WebAppConnection [connection name] [provider] [host:port]WebAppDeploy [application name] [connection name] [url path]  


Where connection name specifies the connection name, provider can only be Warp,port port specified with your tomcat's configuration file server.xml the last few lines to be consistent. Files such as the following:


      
                
       
                ******
      
               


Application name is consistent with the name of the app you deployed in Tomcat, and URL path Specifies the URL of the app. For example, the example above can be used by http://localhost/examples/to access the examples application in Tomcat.

(v): Chinese questions
The general JSP garbled problem can be solved by adding <%@ page contenttype= "text/html;charset=gb2312"%> in the JSP, As for the servlet garbled in the ability to use the Httpserveletrequest.setcharacterencoding function provided in servlet2.3. For more specific Chinese questions, see The Chinese character coding problem in Jsp/servlet .

Four: Overview
As a servlet (JSP is also compiled as a servlet) container, Tomcat is a good prospect, assuming that it is combined with JBoss to implement the Sun's Java EE specification (ejbserver with JBoss). JBoss's official site also offers integrated tomcat3.2* jboss for download. Another open source application server (Enhydra) is Tomcat-based, providing a more user-friendly management interface, easier deployment of applications, and more powerful functions.

References:

    • Tomcat Documentation
    • Tomcat FAQ for www.jguru.com
    • documentation for Apache


about the author
Zong Feng: Master of Computer Science, Northwestern University, interested in a variety of new web-based technologies.


Tomcat Full Guide

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.