Role of Tomcat directory folder ()

Source: Internet
Author: User

(1): directory structure


The directory structure of Tomcat is as follows:
Directory Name Overview
Bin stores startup and shutdown Tomcat scripts
Conf contains different configuration files, server. XML (main configuration file of Tomcat) and Web. xml
Work stores the class files generated after JSP Compilation
The webapp stores the application example, and the application you want to deploy will also be placed in this directory. The. Java file written in the (Package) WEB-INF/src is automatically compiled into the. Class file and transferred to the classes folder under the WEB-INF folder.
Logs stores log files
The LIB/japser/common directories mainly store the jar files required by Tomcat.

(2) server. xml configuration overview

The following describes the basic configuration information in this file. For more detailed configuration information, see the Tomcat documentation.
Element name attribute explanation
Server port specifies a port, which is used to listen for requests to disable tomcat.
Shutdown specifies the command string sent to the port
Service name specifies the service name
Connector (indicating the connection between the client and the Service) Port specifies the port number to be created on the server, and listens to requests from the client on this fracture.
Number of threads created to process requests when the minprocessors server is started
Maxprocessors: Maximum number of threads that can be created to process requests
If enablelookups is true, you can call request. getremotehost () to query the DNS to obtain the actual Host Name of the remote client. If it is false, no DNS query is performed, but the IP address is returned.
Redirectport specifies the port number to be redirected after receiving an SSL transfer request when the server is processing an HTTP request
Acceptcount indicates the number of requests that can be placed in the processing queue when the number of threads that can be used to process requests is used. requests exceeding this number will not be processed.
Connectiontimeout specifies the timeout time (in milliseconds)
Defaulthost specifies the default host name for processing requests. It is at least the same as the name attribute value of one of the host elements.
Context (indicating a web application, usually a war file. For details about war, see servlet specifications) the path of the docbase application or the path where the war file is stored.
Path indicates the prefix of the URL of the Web application. The requested URL is http: // localhost: 8080/path /****
Reloadable this property is very important, if it is true, Tomcat will automatically detect changes to the application's/WEB-INF/lib and/WEB-INF/classes directory, automatically load the new application, we can change the application without restarting tomcat.
Host (indicating a virtual host) Name specifies the Host Name
The basic directory of the appbase application, that is, the directory where the application is stored.
If unpackwars is true, Tomcat automatically decompress the war file. Otherwise, the application runs directly from the war file.
Logger (indicating logs, debugging, and error messages) classname specifies the class name used by logger. This class must implement the org. Apache. Catalina. logger interface
Prefix specifies the prefix of the log file
Suffix specifies the suffix of the log file
If timestamp is true, time is added to the log file name, for example: localhost_log.2001-10-04.txt
Realm (indicating the database that stores the username, password, and role) classname specifies the class name used by realm. This class must implement the org. Apache. Catalina. realm Interface
Valve (similar to logger, its prefix and suffix attributes are interpreted as the same as those in logger) classname specifies the class name used by valve, such as Org. apache. catalina. valves. accesslogvalve class can record application access information
Directory specifies the location where log files are stored
Pattern has two values: Remote Host Name or IP address, user name, date, string of the first line of request, HTTP response code, and number of bytes sent. The combined method has more values than the common method.

Note: 1: After my test, I set the Path = "", reloadable = true of context, and then put a war file to the webapps directory, as a result, Tomcat cannot detect this file (which can be used to restart Tomcat), but decompress the file, Tomcat will automatically detect this new application. If the war file cannot be automatically detected, we can deploy the application using the method described in the following management.

2: Default Server. in XML, the realm element only sets one classname attribute, but this file also contains several examples of connecting to the database through JDBC for verification (which has been removed ), with the realm element, we can implement container management security ).

3: there are still some elements that we haven't introduced, such as parameter and loader. You can get the information of these elements through the Tomcat document.

(3) Management

1: Configuration
Before specific management, we add a user to Tomcat so that the user has the permission to manage the user.

Open the tomcat-users.xml file under the conf directory and add the following line at the appropriate location:

<User name = "admin" Password = "admin" roles = "standard, Manager"/>


Note: the last part of this line must be/>. The/symbol is removed from the Tomcat document. If there is no/symbol, the application cannot be accessed when Tomcat restarts. You can view the error details in the logs/Catalina. Out file.

Restart Tomcat and enter http: // localhost: 8080/manager/in the browser. In the displayed dialog box, enter the above username and password.

2: Application List
Enter http: // localhost: 8080/manager/list in the browser. The browser displays 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 is the application path, the current State (running or stopped), and the number of sessions connected to the program.

3: Reload the application
Enter http: // localhost: 8080/manager/reload in the browser? Path =/examples. The browser displays the following:

OK-reloaded application at context path/Examples


The example application is successfully loaded. if the reloadable attribute of the context element in XML is set to true (see the table above), you do not need to re-load the application in this way because Tomcat will automatically load the application.

4: Display session information
In the browser, enter http: // localhost: 8080/manager/sessions? Path =/examples. The browser displays the following:

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


5. Start and close the application
In the browser, enter http: // localhost: 8080/manager/start? Path =/examples and http: // localhost: 8080/manager/stop? Path =/examples start and close the examples application respectively.

6. Deploy and undeploy
War can be organized in two ways. One is to organize files according to a certain directory structure, and the other is a compressed package suffixed with war. Therefore, war can be deployed in two ways:
(1): Enter http: // localhost: 8080/manager/install in the browser? Path =/examples & war = file:/c: \ examples
Deploy war organized by directory structure

(2): If you enter http: // localhost: 8080/manager/install? Path =/examples & war = jar: file:/c: \ examples. War! /
The war organized by the compressed package will be deployed. Note that the second half of this URL must be available! .

After deployment, you can use http: // localhost: 8080/examples for access.

In the browser, enter: http: // localhost: 8080/manager/remove? Path =/Examples
The deployed application will be revoked.

(4) integration with Apache

Although Tomcat can also be used as a Web server, its processing speed of static html is not as high as that of Apache, and its function as a web server is far inferior to that of Apache. Therefore, we want to integrate Apache and tomcat.

We will take Linux as an example.

Download the source code version apache1.3.22 from the Apache website and run the following command to install Apache:

Mkdir/usr/local/apachetar zxvf apache.1.32.tar.gz CD apache.1.32./configure -- prefix =/usr/local/Apache -- enable-module = So Makemake install


Note that the configure command specifies the target installation directory and is supported by DSO (dynamic shared object). Do not forget this option.

Download the webapp module, decompress the mod_webapp.so file, and put it to the libexec directory of Apache. Edit httpd. conf under the conf directory of Apache. Add the following three lines at the end of the file:

Loadmodule webapp_module libexec/mod_webapp.sowebappconnection warpconnection warp localhost: 8008 webappdeploy examples warpconnection/examples/


The first line is to add the webapp module. If DSO support is not added during Apache compilation, the loadmodule command cannot be used. The second line specifies the connection between Tomcat and Apache, and the third line specifies the application to be deployed, the two commands are in the following format:

Webappconnection [connection name] [provider] [host: Port] webappdeploy [Application name] [connection name] [URL path]


The connection name specifies the connection name. The provider can only be warp, and the port must be consistent with the last few lines of your tomcat configuration file server. xml. The file is as follows:

<Service name = "tomcat-Apache"> <connector classname = "org. apache. catalina. connector. warp. warpconnector "Port =" 8008 "minprocessors =" 5 "maxprocessors =" 75 "enablelookups =" true "acceptcount =" 10 "DEBUG =" 0 "/> ****** </service>


The Application name is the same as the application name deployed in Tomcat. The URL path specifies the URL to access this application. For example, you can use http: // localhost/examples/to access the examples application in Tomcat.

(5): Chinese

Generally, you can add <% @ page contenttype = "text/html; charset = gb2312" %> to solve the JSP garbled problem, as for servlet garbled characters, you can use the httpserveletrequest provided in servlet2.3. setcharacterencoding function.

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.