Configuration of environment variables

  • User variables are similar to local variables, and system variables are similar to global variables. You are advised to configure them in user variables
  1. Add the Tomcat installation directory

    2. Configure Path so that the executable files in the bin folder can be accessed in any Path

Startup and shutdown of Tomcat

The target

  1. Commands to start and stop Tomcat
  2. Tomcat for each directory

Start and close commands

If Path is configured, you can run the two commands in any directory. If Path is not configured, you can run the two commands in the tomcat/bin directory.

  1. Start command: startup.bat
  2. Shutdown command: shutdown.bat

Solve garbled code problems

  1. Modify the C: \ apache tomcat — 8.5.51 \ conf \ logging properties
  2. Open and replace all UTF-8 with GBK

Common problems during Tomcat startup

The target

Two common startup problems

Problem 1: The JAVA_HOME environment variable is not set

Because Tomcat is also written in Java, it must run in the JVM

  1. An error message

    2. Solutions

Fault 2: The port number is occupied

  1. Note: The default tomcat port number is 8080. Ensure that this port number is not occupied
  2. View log files: Logs are also recorded in the logs directory
  3. Solutions:
    1. Method 1: find the program that occupies the port number and kill the process.

1Open the conf/server. XML file2Found.69Line,8080Change to another port number:8888
 <Connector port="8080" protocol="HTTP / 1.1"
             connectionTimeout="20000"
             redirectPort="8443" />
3. Restart Tomcat. Note: Tomcat needs to be restarted whenever server. XML is modifiedCopy the code

There are three ways to release Tomcat projects

Distribution method 1: Copy to Webapps

Operation method

  1. Copy the project directly to the Webapps directory

  2. Use compressed file. War

    1. Go to the project directory, excluding the top-level folder

    2. Package the entire project into a ZIP file using a compression tool

  1. Change the extension of zip to war

  2. Copy it to the webapps directory and Tomcat will automatically decompress it into a directory with the same name.

Release Mode 2: Virtual directory

The principle of

Specify a virtual address in the server.xml configuration file that points to a real directory on the server

Configuration mode

Locate the host element in server.xml and add the following configuration

Context element attributes instructions
path Specify a virtual address that is accessed from the browser
docBase Points to the real directory on the server

Advantages: There is no need to copy files, so there are not too many projects in the Webapps directory, which affects the tomcat startup speed

steps

  1. Open conf/server. XML

  2. Locate the host element on line 152

  3. Add a child element Context containing two attributes: path and docBase

<Host name="localhost"  appBase="webapps"
	unpackWARs="true" autoDeploy="true">Note: There must be an end /<Context path="/heima" docBase="e:/heima" />	   

</Host>
Copy the code

Distribution method 3: Independent XML file

Note: The previous two methods require tomcat to be restarted, which is the default method in IDEA.

This is similar to approach 2, except that approach 2 is configured in the server.xml file, which has a separate XML configuration file for each project

steps

  1. In tomcat/conf/catalina/localhost create XML configuration files
  2. The name is assumed to be: second.xml, which is the access path for the project
  3. Add the content of the XML file as
<Context  docBase="Project directory" />
Copy the code