Tomcat configuration and deployment

The http protocol is the communication protocol between the http client and the http server, and Tomcat is the most widely used http server in the java circle.

Download Tomcat

Tomcat official website

The version of Tomcat is strongly related to the subsequent servlet version. Here, tomcat 8 is used, and the corresponding servlet is 3.1

image-20230405142119959

Download a zip archive and decompress it

image-20230405142629585

Tips: tomcat is implemented by java, which requires JDK and JRE on the computer, but the higher version of JDK does not contain JRE, if it cannot run, you can try to reconfigure JRE.

If the tomcat window flashes by, there are many reasons for the error. Drag the .bat program into cmd and run it to see the error message. The most typical reason is that the environment variable is not configured. (JAVA_HOME, JRE_HOME, CATALINA_HOME…) Configure whichever is missing.

image-20230405143747198


start tomcat

Find startup.bat in the bin directory, double-click it to start it.

image-20230405144040200

The content code in the red box in the figure below appears. The tomcat startup is successful. The main reason for the garbled characters is that the default encoding format of the cmd window is GBK. This problem will not occur if you use other methods to start tomcat later.

image-20230405144302706


Visit the welcome page of tomcat

Enter 127.0.0.1:8080 in the browser address bar, and the welcome page of tomcat will pop up. (The premise is to run tomcat)

image-20230405144704819

127.0.0.1 is the loopback IP, 8080 is the default port number of tomcat (equivalent to the default port number of MySQL is 3306)


How to use Tomcat

The biggest use of tomcat is to deploy the written website to the tomcat server.

Website = Frontend + Backend.

We can package and copy the front-end code to the webapps directory. (need to restart tomcat)

After that, you can access the front-end page through the browser.

image-20230405145817069

Tips: The path in the address bar must correspond to the file path in webapps

image-20230405150414961


Advantages of Tomcat Deployment

After the code is deployed to the tomcat server, it is equivalent to accessing resources through the network, while it was accessed through the file path before. The biggest advantage of accessing through the network is that it can be cross- hosted .

But at this time, the webpage deployed in tomcat cannot be accessed by others, and requires an external network IP. The easiest way to obtain an external network IP is to buy a cloud server for deployment. The subsequent servlet chapter will explain cloud server deployment in detail.

Guess you like

Origin blog.csdn.net/liu_xuixui/article/details/130313836