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

Source: Internet
Author: User
Tags command line current time temporary file storage xmlns zip root directory tomcat tomcat server

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)

Ii. Installation of JDK

Click the JDK application default installation and note the JDK's installation directory (for example: C:\Program files\java\jdk1.7.0_45).

Iii. Configuring JDK and Tomcat

1. Configuring the JDK

After the JDK installation is complete, you need to configure the environment variables and create two new environment variables in the system variables, environment variables, advanced system settings, properties, and so on (computer): Java_home and Classpath. The value of the variable in the Java_home is populated with the JDK installation directory, in turn, as shown below:


The variable value in the classpath is filled in.; %java_home%\lib\dt.jar;%java_home%\lib\tools.jar; (.; Must not be less, because it represents the current path), in order to determine, the following figure:


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




2. Configure Tomcat (for example: apache-tomcat-6.0.39)

Download apache-tomcat-6.0.39 and rename it to Tomcat, and put it in a directory (e.g. C:\Program files\tomcat). New environment variable Tomcat_home in the system variable, environment variable, advanced system settings, properties, and so on, the variable value fills in the directory of Tomcat, in turn, as shown below:


Then modify the system variables in the Classpath, the Tomat installation directory in the Lib Servlet-api.jar appended to the classpath, after the value of the variable added%tomcat_home%\lib\ Servlet-api.jar (note: With other environment variables with ";" Interval), in turn, as shown below:


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


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

Open a command line Prompt window, enter the Tomcat installation directory, enter the bin directory, input: Service.batinstall, as shown, the Tomcat directory on your computer can be


This lets tomcat display the console in window mode. Click on the Tomcat6w.exe and it will appear as shown below:


Click Start to start the Tomcat service, if Startuptype Select Automatic, it will start up with the boot, so you do not need to manually open each time.

Iv. build your own JSP app directory

1. To the WebApps directory of the Tomcat installation directory, you can see some directories such as Root,examples, Tomcat-docs and other Tomcat.

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

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

4. Create a new file, Web. Web-inf under the following text:

<?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. Create a new test JSP page under MyApp with the file name index.jsp and the file content 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:


V. TOMCAT directory structure
1. First Level Catalogue
Bin--tomcat executing the script directory
Conf--tomcat configuration file
Lib--tomcat running the required library files (JARS)
Logs--tomcat log file at execution time
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 will translate the JSP file into the Java file and the class file here.
2. Level two directory (only a few important files are listed in the first level directory)
(1) file in Bin directory
Catalina.sh for starting and shutting down the Tomcat server
configtest.sh for checking configuration files
Startup.sh launching the Tomcat script
shutdown.sh Close Tomcat Script
(2) files under the Conf directory
Server.xml Tomcat Global configuration file
Web. XML sets default files for different tomcat-configured websites
Tomcat-users.xml Tomcat User-certified configuration file
(3) files in Lib directory
Contains a variety of jar files used by Tomcat.
(4) files 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 log files
(5) files under the WebApps directory
Programs with Web Apps (JSP, servlet, JavaBean, etc.)
(6) files under the work directory
Automatically generated by Tomcat, which is where Tomcat places the intermediate (intermediate) files (such as compiled JSP files) during its run. 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)
The second-level directory WebApps, which primarily hosts Web applications. The Tomcat Web application should consist of the following directories:
(1). page content and other files storage location: *.html, *.jsp, etc. can have many directory levels, by the user's 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, as well as 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, including some initialization information and security constraints, and so on.
(3).         Web-inf/classes/this directory and its subdirectories should include all compiled Java class files (*.class) files, such as all JavaBean and servlets for this Web application, as well as those that have not been compressed into the jar package His class files and related resources. Note that the Java class in this directory should organize the directory according to the package hierarchy to which it belongs (that is, if the *.class file has a package definition, the *.class file should be placed under the. \web-inf\classes\ package name).
(4). Usually web-inf/classes/the class file in this directory can also be packaged into a jar file, and can be placed in the Web-inf under the Lib directory. 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 Web-inf is not in the public document root directory. The files contained in this directory cannot be accessed by the client.
• The class directory (under Web-inf) contains classes such as the Servlets,beans that are required to run the Web application.
The Lib directory (under Web-inf) contains Servlets,beans files for Java archive files (JARs), such as tag libraries or *.jar classes.
• If a class appears in the jar file and also appears in the directory of the class, the ClassLoader loads the one that is located in the class directory.
(5). common/lib/This directory contains all the class files and related files that are compressed into the jar file. For example: Java library files provided by third parties, JDBC drivers, etc.
• JDBC driver where Msbase.jar, Mssqlserver.jar, msutil.jar files are SqlServer2000
• Packages where Servlet-api.jar and Jsp-api.jar are the APIs for Servlets and JSPs
Vi. Tomcat configuration Files
The tomcat configuration file is stored in the $catalina_home/conf directory by default, mainly in the following categories:
Server.xml:tomcat's main configuration file, including the service, Connector, Engine, Realm, Valve, hosts the main components of the relevant configuration information;
web.xml: A configuration file that follows the servlet specification, configures the servlet, and provides default configuration information, including MIME mappings, for all Web applications;
Tomcat-user.xml:realm The relevant roles, users and passwords used in the authentication; the manager will use this file by default, adding/removing users in Tomcat, assigning roles to users, etc. will be implemented by editing this file;
Catalina.policy:java The relevant security policy configuration file, providing access control capability at the system resource level;
Catalina.properties:tomcat the definition of the internal package and access-related controls, as well as control over what is loaded through the class loader; Tomcat will read the relevant settings of this file in advance;
Logging.properties:tomcat Records the operation-related logs through its own internally implemented Java logger, which is a log logger-related configuration information that can be used to define the component level of the logging and the location of the log file;
context.xml: Default configuration information for all host;
Here are a few of the most common configuration files.
1. Server.xml
Tomcat runs in an object-oriented manner, which can dynamically load the object structure defined in the configuration file at run time, which is somewhat similar to how Apache's httpd module is called. Each primary element defined in Server.xml is created as an object and organized together in a specific hierarchy. Here is a diagram illustrating the relationship between the components.

There are very many definable elements in the Server.xml file, 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 connector separately for the 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.
There are several properties that define a connector, and some properties apply only to a particular connector type. Generally speaking, there are 4 kinds of connector types commonly found in Server.xml:
HTTP Connector
SSL Connector
AJP 1.3 Connector
Proxy Connector
HTTP connectors as defined in Server.xml:

            <connector port= "8080" protocol= "http/1.1" 
                   connectiontimeout= "20000" 
                   redirectport= "8443" URIEncoding= " UTF-8 "/>
(2). Context Components
The context is similar in some sense to the path alias in Apache, a context definition used to identify a Web application in a 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 made using a separate XML file whose directory is $catalina_home/conf/<engine name>/Common properties are defined as:
Docbase: The location of the corresponding Web application, or a relative path, the path defined by the AppBase in the host to which this context belongs, and remember that the path name of DocBase cannot be associated with the path name defined in AppBase in the corresponding host There is a containment relationship, for example, if AppBase is a deploy, and docbase must not be the name of the Deploy-bbs class;
path: A URI relative to the root path of the Web server, or a root path for this webapp if NULL "", if the context is defined in a separate XML file, this property does not need to be defined;
reloadable: If the class for this context-dependent Web application is allowed to reload, the default is false;
2. Web. xml
Web. XML is based on the Java servlet specification and can be used in every Java servlet container, typically with two storage locations, $CATALINA _base/conf and each Web application (typically Web-inf/web.xml). When Tomcat is deploy an application (including rebooting or re-loading), it reads Conf/web.xml first and then reads 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.