Tomcat Learning II: Tomcat installation, configuration and directory file description

Source: Internet
Author: User
Tags current time temporary file storage xmlns zip tomcat

First, download JDK and Tomcat

Website JDK Address: http://java.sun.com/javase/downloads/index.jsp

Official website Tomcat address: http://tomcat.apache.org/download-60.cgi (apache-tomcat-6.0.39), download 32-bitwindows zip or 64-bitwindows Zip (depends on your computer configuration)

Second, the installation of JDK

Click on the JDK application default installation to note the installation directory of the JDK (for example: C:\Program files\java\jdk1.7.0_45).

Iii. Configuring JDK and Tomcat

1. Configure JDK

After the JDK installation is complete, you need to configure environment variables to create two new environment variables in the computer-> Properties-> advanced system settings-> environment variables-> System variables: Java_home and classpath. Variable values in Java_home the installation directory of the JDK, determined in turn, as shown in the following figure:


The variable value in the Classpath.; %java_home%\lib\dt.jar;%java_home%\lib\tools.jar; (.; Must not be less because it represents the current path), determined in turn, as shown in the following figure:


Then locate the path in the system variable, edit it, and add%java_home%\bin to the path (note: With other environment variables with ";" Interval
Test the success of the JDK configuration, win hotkey +r open the Run window input cmd, input Java, Javac and java-version on the command line, and if the following information is displayed, the JDK configuration is successful




2. Configure Tomcat (such as: apache-tomcat-6.0.39)

After downloading the apache-tomcat-6.0.39, and renaming it to Tomcat, put it in a directory (such as: C:\Program Files\tomcat). In the computer-> Properties-> advanced system settings-> environment variable-> system variable tomcat_home, whose variable value is filled in the directory of Tomcat, determined in the following figure:


Then modify the classpath in the system variable, append the Servlet-api.jar in the Tomat installation directory to the CLASSPATH, add%tomcat_home%\lib\ after the value of the variable Servlet-api.jar (note: With other environment variables with ";" Interval), determined in turn, as shown in the following figure:


Then find Startup.bat in C:\Program files\tomcat\bin, double-click to start Tomcat, and then enter http://localhost:8080in the browser, If the window with the kitten is configured Tomcat success, as shown in figure:


We see a tomcat6w.exe in the Tomcat Directory/bin folder, as the name suggests that Tomcat displays the console in window mode. The 1th time you click to open it, you may be prompted: Tomcat specified service is not installed, this time we can resolve it.

Open the command Line Prompt window-> Enter the Tomcat installation directory-> enter the bin directory-> input: Service.batinstall can, as shown in the operation, Tomcat directory on their own computer to be able to


This allows Tomcat to display the console in window mode. Click Tomcat6w.exe and it will appear as shown:


Click Start to start the Tomcat service, if the Startuptype select Automatic, it will start with boot, so do not need to manually open every time.

Four, set up their own JSP app directory

1. To the WebApps directory of Tomcat's installation directory, you can see some directories of Tomcat from Root,examples, Tomcat-docs, etc.

2. Create a new directory under the WebApps directory, named MyApp;

3. MyApp a new directory web-inf, note that the directory name is case-sensitive;

4. Under Web-inf, create a new file Web.xml, which reads as follows:

<?xml version= "1.0" encoding= "iso-8859-1"?> <web-app xmlns=

"Http://java.sun.com/xml/ns/javaee"
   Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemalocation= "http://java.sun.com/xml/ns/ Java ee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd "
   version=" 2.5 >

  <display-name>my Web Application</display-name>
  <description>a Application for test</description>
  < welcome-file-list>
    <welcome-file>login.jsp</welcome-file>
  </welcome-file-list>
</web-app>

5. Under MyApp, create a new JSP page for the test, the file name is index.jsp, and the contents are as follows:

 

6. Restart Tomcat

7. Open the browser, enter http://localhost:8080/myapp/index.jsp to see the current time, the description is successful. The following figure:


Five, Tomcat directory structure
1. First Level Catalogue
Bin--tomcat Execute script Directory
Conf--tomcat configuration file
Lib--tomcat run the required library files (JARS)
Log file for logs--tomcat execution
Temp--tomcat Temporary File storage directory
Webapps--tomcat's main Web publishing directory (store our own Jsp,servlet, Class)
Work--tomcat's working directory, Tomcat puts the translation JSP files into the Java files and class files here.
2. Level two directory (only a few important files listed in the first level of directory)
(1) files in bin directory
Catalina.sh for starting and shutting down Tomcat servers
Configtest.sh used to check configuration files
startup.sh Start Tomcat Script
Shutdown.sh Turn off Tomcat script
(2) files under the Conf directory
Global configuration file for Server.xml Tomcat
Web.xml a file that sets the default value for different tomcat-configured Web applications
Tomcat-users.xml Tomcat User-certified configuration file
(3) files in Lib directory
Contains various jar files that are used by Tomcat.
(4) Documents under the logs directory
Localhost_access_log.2013-09-18.txt Access Log
Localhost.2013-09-18.log Errors and other logs
Manager.2013-09-18.log Management Log
Catalina.2013-09-18.log Tomcat to start or close the log file
(5) Documents under the WebApps directory
Programs with Web applications (JSP, servlet, JavaBean, etc.)
(6) Documents under the work directory
Automatically generated by Tomcat, which is where Tomcat places the intermediate (intermediate) files (such as compiled JSP files) during which it runs. If you delete this directory when Tomcat is running, you will not be able to execute the page that contains the JSP.
3. Level three directory (only for directories or files under Level two directory WebApps)
Second-level directory WebApps, the main storage of Web applications. The Tomcat Web application should consist of the following directories:
(1). Page content, such as file storage location: *.html, *.jsp, etc. can have a number of directory levels, by the user's Web site structure, the implementation of the function should be the interface of the site, that is, the user's main visible part. In addition to HTML files, JSP files, there are JS (JavaScript) files and CSS (style sheet) files and other multimedia files.
(2). Web-inf/web.xml This is a description file for a Web application. This file is an XML file that describes the servlet and other component information for this Web application, in addition to some initialization information and security constraints, and so on.
(3).         Web-inf/classes/this directory and its subdirectories should include all JavaBean and Servlet-Compiled Java class file (*.class) files for this Web application, and their His class files and related resources. Note that the Java class in this directory should organize the directory according to the package hierarchy it belongs to (that is, if the *.class file has a package definition, the *.class file should be placed under the. \web-inf\classes\ package name).
(4). Normally web-inf/classes/the class files in this directory can also be packaged into jar files and can be placed under the Lib directory under Web-inf. If you package each *.class file in the classes directory as a Webmis.jar file (jar CVF Webmis.jar *.*)
Description
The Web-inf directory contains the resources used by the application, but the Web-inf is not in the public document root directory. The files contained in this directory cannot be accessed by the client.
• Class directory (under Web-inf) contains classes such as the Servlets,beans required to run a Web application.
The Lib directory (under Web-inf) contains the Java Archive files (JARs), such as Servlets,beans files for classes such as tag libraries or *.jar.
• If a class appears in the jar file and also appears in the class's directory, the class loader loads the one in the class directory.
(5). common/lib/This directory contains all class files and related files that are compressed into a jar file. For example, a third party provides Java library files, JDBC drivers, and so on.
• JDBC driver with Msbase.jar, Mssqlserver.jar, Msutil.jar files as SqlServer2000
• Packages where Servlet-api.jar and Jsp-api.jar are the APIs for the servlet and JSP
VI. Tomcat configuration file
The tomcat configuration file is stored by default in the $catalina_home/conf directory, mainly in the following categories:
Server.xml:tomcat The main configuration file, including service, Connector, Engine, Realm, Valve, hosts the main components of the relevant configuration information;
web.xml: A configuration file that follows the Servlet specification standard for configuring the servlet and providing default configuration information, including MIME mappings, for all Web applications;
Tomcat-user.xml:realm The relevant roles, users and passwords used in the authentication; Tomcat's own manager will use this file by default; Add/Remove Users in Tomcat, assign roles to users, etc. will be implemented by editing this file;
Catalina.policy:java The relevant security policy profile to provide access control capabilities at the system resource level;
Catalina.properties:tomcat Internal package definition and access control, also includes control over content loaded through the class loader; Tomcat reads the relevant settings for this file in advance when it starts;
Logging.properties:tomcat Records the operation-related logs through its own internally implemented Java logger, which is the configuration information related to the logger, which can be used to define the component level of the log records and the location of the log files;
context.xml: Default configuration information for all host;
The following is a detailed explanation of several common configuration files.
1. Server.xml
Tomcat runs in an object-oriented fashion, and it can dynamically load the object structure defined in the configuration file at run time, which is somewhat analogous to how the Apache httpd module is invoked. Each of the main elements defined in Server.xml are created as objects and are organized together in a particular hierarchy. Here is a schematic showing the relationships between the components.

Server.xml files can be defined in a number of elements, including server, Service, Connector, Engine, Cluster, Host, Alias, Context, Realm, Valve, Manager, Listen Er, resources, Resource, Resourceenvref, ResourceLink, Watchedresource, Globalnameingresources, Store, Trans Action, Channel, membership, transport, member, Clusterlistener, etc.
A few common components are briefly described below:
(1). Connector components
Tomcat should consider the work situation and define the required connectors for each request in the appropriate case to receive requests from the client correctly. An engine can have one or more connectors to accommodate a variety of request methods.
You can define a connector with a variety of properties, and some properties apply only to a particular connector type. Generally, there are 4 types of connectors commonly found in Server.xml:
HTTP Connector
SSL Connector
AJP 1.3 Connectors
Proxy Connector
HTTP connectors as defined in Server.xml:

            <connector port= "8080" protocol= "http/1.1" connectiontimeout= "20000" redirectport= "8443" 
                   UTF-8 "/>
(2). Context Component
The context is similar in some sense to the path alias in Apache, a context definition used to identify a Web application in the Tomcat instance, as defined below:
<!--Tomcat Root context-->
<context path= "" docbase= "/web/webapps"/>
<!--Buzzin WebApp-->
<context path= "/bbs"
docbase= "/web/threads/bbs"
reloadable= "true" >
</Context>
<!--chat server-->
<context path= "/chat" docbase= "/web/chat"/>
<!--Darian Web-->
<context path= "/darian" docbase= "Darian"/>
In Tomcat, each context definition can also be performed using a separate XML file whose directory is $catalina_home/conf/<engine name>/The commonly used attribute definitions are:
Docbase: The location of the corresponding Web application, or the relative path, where the starting path is defined for AppBase in the context-owning host; Remember that the docBase pathname cannot be the path name defined in the corresponding host AppBase Contains a relationship, for example, if AppBase is deploy, and docbase cannot be the name of Deploy-bbs class;
path: A URI relative to the root path of the Web server, or null "" to represent the root path of this webapp; If the context is defined in a separate XML file, this attribute does not need to be defined;
reloadable: Allows you to reload the class for this context-related Web application, default to False;
2. Web.xml
Web.xml is based on the Java servlet specification and can be used for each Java servlet container, typically with two storage locations, $CATALINA _base/conf and each Web application (usually Web-inf/web.xml). When Tomcat deploy an application (including reboot or reload), it reads the conf/web.xml first and then reads the Web-inf/web.xml.

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.