Tomcat summary


1. Overview

Tomcat is simply a network server running Java. The bottom layer is a program of socket and a container of servlet

Tomcat summary
Tomcat summary

2. Structure catalog

Tomcat summary
1. Bin — start and close the bat file of Tomcat
2. Conf — configuration

Server.xml configure server related information, such as port number, host

3. Lib — put the jar package needed to run Tomcat
4. Logs — store logs
5. Webapps — store our web applications
6. Work working directory — this directory stores server files and. Class files

3. Detailed description of webapps directory (key points)

Tomcat summary
This setting site directory is to modify the HTML file as the first page of the site.
Without the support of web.xml file, it can not meet the requirements. At the same time, this standard is conventional.

Configuration access home page

1. First, create a new WEB-INF directory
2. Create a web.xml in the WEB-INF directory, and the code can be copied directly from other existing ones.
3. Add the following code to web. XML




Virtual directory

1. If all the web site directories are placed under webapps, it may lead to insufficient disk space, and it is not conducive to the management of the web site directory (in fact, the physical directory of the website, that is, the real directory) (assuming that there are many web site directories)
2. To distribute the directory of a web site (composed of a group of HTML documents, media files and related directory structure, focusing on information browsing) to other disks, you need to configure a virtual directory (by default, only the directory under webapps can be automatically managed as a web site by Tomcat)
3. The directory of web application is managed by web server, which is called virtual directory mapping.

Method 1 of configuring virtual directory

1. Create a web site directory under other drive letters, and create a WEB-INF directory and an HTML file.
2. Find the / conf / server.xml file in the Tomcat directory
3. Add the following code to the node in server.xml. Path represents the name of the web project entered during the access, and docbase is the absolute path of the site directory
<context path="/web1" docBase="D:
Access the configured web site directory

Method 2

Enter the file conf / Catalina / localhost and create an XML file. The name of the file is the name of the site.
The code of the XML file is as follows. Docbase is the absolute path of your web site.

<?xml version="1.0" encoding="UTF-8"?>

Configure temporary domain name

Win step: find the hosts file in C: windows, system32, drivers, etc
Tomcat summary

Set up virtual host

1. What is virtual host

Multiple websites with different domain names coexist in one Tomcat

2. Why use virtual host

Example: I have now developed four websites with four domain names. If I don't configure a virtual host and a Tomcat server runs a website, I need four computers to run the four websites.

3. Configuration steps

Add the host name to the server. XML file of Tomcat
    1. <Host name="zhongfucheng" appBase="D:web1">
    1. <Context path="/web1" docBase="D:web1"/>
    2. </Host>

    Tomcat summary
    Tomcat summary
    The project that we usually run in idea is not in webapps under Tomcat installation directory. Instead, we store the configuration file in /. Intelijidea / system. After starting tomcat, we run to read our configuration file, so as to complete a deployment of the complete project.
    Tomcat summary
    Tomcat summary
    That is the second configuration method of virtual directory described above
    Reference blog…
    This article refers to the blog of java3y to learn from the boss