Tomcat Server Detailed

Source: Internet
Author: User

1 Tomcat Overview

Tomcat server is provided by Apache and open source is free. Because Sun and other companies are involved in Tomcat development, the latest Jsp/servlet specification is always available in Tomcat. Currently the latest version is TOMCAT8, and we use TOMCAT7 in our course. TOMCAT7 supports Servlet3.0, and TOMCAT6 only supports servlet2.5!

2 Installing, starting, and configuring Tomcat
下载Tomcat可以到http://tomcat.apache.org下载。Tomcat分为安装版和解压版:?安装版:一台电脑上只能安装一个Tomcat;?解压版:无需安装,解压即可用,解压多少份都可以,所以我们选择解压版。

2.1 Tomcat directory structure

For installation of Tomcat, please refer to day03_res/tomcat installation. doc file.
Unzip the version of Tomcat to a non-Chinese, no space in the path, it is recommended that the path is not too deep, because we need to frequently enter the Tomcat installation directory. Example: F:\apache-tomcat-7.0.42

2.2 Starting and shutting Tomcat

Before we start Tomcat, we have to configure the environment variables:
? Java_home: The Java_home must be configured first, because the Tomcat boot requires the use of the JDK;
? Catalana_home: In the case of the installation version, you also need to configure this variable, which is used to specify the installation path for Tomcat, for example: F:\apache-tomcat-7.0.42.
Start: Enter%catalana_home%\bin directory, find startup.bat[Open Server], double-click can;
Close: Enter%catalana_home%\bin directory, find shutdown.bat[shut down server], double click can;
Startup.bat calls Catalina.bat, and Catalina.bat calls Setclasspath.bat,setclasspath.bat uses the JAVA_HOME environment variable, So we have to configure the java_home correctly before starting Tomcat.
Startup issues:
After clicking Startup.bat, the window disappears: Check that the JAVA_HOME environment variable is configured correctly;

2.3 Entering the Tomcat home page

Visit: http://localhost:8080

2.4 Configuring port Numbers

Open%catalana_home%\conf\server.xml File:

The HTTP default port number is 80, which means that port numbers are used when the port number is not given in the URL. 80. Of course you can also modify the other port number.
When you change the port number to 80, you only need to enter it in the browser: http://localhost can access the Tomcat home page.

2.5 Tomcat's directory structure

? Bin: This directory is a binary executable file, if the installation version, then this directory will have two EXE files: Tomcat6.exe, Tomcat6w.exe, the former is launched in the console tomcat, the latter is the popup ugi window to start Tomcat, if it is the decompression version, then there will be Startup.bat and shutdown.bat files, Startup.bat used to start Tomcat, but need to first configure Java _home environment variable to start, Shutdawn.bat to stop tomcat;?conf: This is a very, very important directory with four of the most important files:? Server.xml: Configure the entire server information. For example, modify the port number, add a virtual host, and so on; Tomcatusers.xml: Stores the Tomcat user's file, which is where Tomcat's username and password are stored, as well as the user's role information. You can add a tomcat user by following the comment information in the file, and then you can go to the Tomcat Manager page in the Tomcat homepage; web. XML: The deployment descriptor file, which registers many MIME types, the document type. These MIME types are document types that are documented between the client and the server, such as when a user requests an HTML page, and the server also tells the client that the browser responds with a text/html type of document, which is a MIME type. The client browser knows how to handle it through this MIME type. This HTML file is, of course, displayed in the browser. However, if the server responds to an EXE file, then the browser will not be able to display it, but should pop up the download window. MIME is used to describe what type of content the document is!?context.xml: Unified configuration for all applications, usually we do not configure it. Lib:tomcat's class library, which is a bunch of jar files. If you need to add a tomcat-dependent jar file, you can put it in this directory, of course, you can also put the application dependent jar files in this directory, this directory of jar all items can be shared, However, it is not possible to share the jar package in this directory when your application is placed under other tomcat, so it is recommended that only the jar packages that Tomcat needs are placed in this directory; logs: This directory is a log file that logs information about Tomcat startup and shutdown, If there is an error starting Tomcat, the exception is also recorded in the log file. Temp: A temporary file for tomcat that can be deleted after you stop Tomcat!?webapps: The directory where the Web project is stored, each folder is aItems, if a directory already exists in this directory, then it is all Tomcat's own. Project. Where Root is a special project and the project directory is not given in the address bar, the root project is the corresponding one. Http://localhost:8080/examples, enter the sample project. Where examples is the project name, the name of the folder. Work: The files that are generated at run time, and the files that are eventually run are here. Generated by the project in WebApps! You can delete the contents of this directory and run it again to generate the work directory again. When a client user accesses a JSP file, Tomcat generates a Java file from the JSP and then compiles the Java file to generate the class file, and the resulting Java and class files will be stored in this directory. LICENSE: License.? NOTICE: Description file.
3 Configuring external applications (Learn)

Originally our project put under WebApps, now I put outside, also hope Tomcat can find it!
You can also put apps outside of Tomcat, which is an external application. For example, we cut the Hello application written above from the WebApps directory to the C drive, i.e. C:/hello. Now that the web app for Hello is no longer in Tomcat, we need to configure the location of the external app in Tomcat in a total of two ways:
Conf/server.xml: Open the Server.xml file, locate the element, add the element in it, and the code is as follows:
Server.xml

1) Path: Specifies the name of the current app;
2) DocBase: Specify the physical location of the application;
3) Browser access path: http://localhost:8080/itcast_hello/index.html.
Conf/catalana/localhost: Create a Itcast_hello.xml file in this directory, write the elements in the file, with the following code:

1) file name: Specifies the name of the current app;
2) DocBase: Specify the physical location of the application;
3) Browser access path: http://localhost:8080/itcast_hello/index.html.

Tomcat Server Detailed

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.