JavaEE Elementary - Tomcat download and use

What is Tomcat


Tomcat is an HTTP server .
The HTTP protocol is the format of the interactive data between the HTTP client and the HTTP server , and the HTTP client is constructed respectively through ajax and Java Socket .

We can also implement the HTTP server through Java Socket, and Tomcat
is an open source, free and widely used HTTP server based on Java .

Download and install


1. Search for tomcat, and look for the following domain name.


2. Select the Tomcat 8 version under Download.


3. Choose to download the Zip package in the current circle, and extract it to the current folder.






Double-click to open the unzipped file.



bin represents an executable program/script, which is used to start tomcat.

conf is used to change the configuration, using xml format to represent the configuration of the server. For example, if you want to change the binding port number of tomcat,
you need to change the content here.

logs is the running log of tomcat. If there is a problem with the program, you need to read this log.

lib is some libraries that tomcat depends on, which is not considered at this time.

Each webapp is a website, and multiple websites can be deployed on one tomcat, which is called "webapps" here .
There are many directories included here, and each directory is regarded as an independent website.

start tomcat


1. Open the bin directory.


2. Find the startup.bat file and double-click to open it.



You can see that there are two similar files, startup.bat and startup.sh .
The first one is for windows and the second one is for linux and mac.




Seeing the part circled above means that the startup is successful.

Visit the welcome page of tomcat


Next, visit the welcome page of tomcat, which is a webapp that comes with tomcat.



8080 is the default port number of tomcat, similar to the port number of myaql is 3306.
The default port number can be modified, but it is not necessary to modify it at present.



The above is the welcome page of tomcat, the premise of visiting is that tomcat is open.

Deploy the previous code to tomcat


Deployment is just copying the code to the webapps directory, but you may need to restart tomcat.



Copy the code of the blog front-end page written before to the webapps directory.



At this point, you can access the blog page through the browser.



If there is a problem with the path, a 404 not found status code will be reported.


The difference between opening with a browser as above and double-clicking to open in a file is that the former is accessed by asking for directions , and the latter is accessed by file paths .

Back-end development of the website based on tomcat


The back-end development of the website based on tomcat definitely requires a series of operations for the http protocol.
Tomcat has already encapsulated these http-related bottom-level operations. At this time, we only need to call the api provided by tomcat .


The api here refers to servlet , which is the native web development api provided by tomcat for java.

This servlet will be introduced next time.



insert image description here

Guess you like

Origin blog.csdn.net/m0_63033419/article/details/130020997