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
The version of Tomcat is strongly related to the subsequent servlet version. Here, tomcat 8 is used, and the corresponding servlet is 3.1
Download a zip archive and decompress it
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.
start tomcat
Find startup.bat in the bin directory, double-click it to start it.
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.
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)
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.
Tips: The path in the address bar must correspond to the file path in webapps
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.