Getting Started with Tomcat
Tomcat overview
Tomcat server is a free and open source Web application server. It is a lightweight application server. It is widely used in small and medium-sized systems and occasions where there are not many concurrent users. It is the first choice for developing and debugging JSP programs.
Servlet and JSP specifications are supported, and the latest Servlet and JSP specifications are always reflected in Tomcat.
The Apache Software Foundation has two commonly used software: apache web server and tomcat web server.
1. The apache web server specializes in processing HTML pages.
2. The tomcat web server can handle not only servlets and jsp, but also html pages, but not as good as the apache web server.
3. In development, tomcat is generally used to process servlets and jsp, and apache server is used to process html pages. And apache and tomcat are used together.
Using Tomcat server
Install
- Download a tomcat server software
https://tomcat.apache.org/download-90.cgi - Unzip the downloaded compressed
package and copy the unzipped file to a path without Chinese characters and spaces.
For example: C:\dev_soft\apache-tomcat-9.0.2
Directory Structure
bin: script directory
startup script: startup.bat
stop script: shutdown.bat
conf: configuration file directory
core configuration file: server.xml
user rights configuration file: tomcat-users.xml
default configuration file for all web projects: web.xml
lib: Dependent library, jar package
logs that need to be used in tomcat and web projects: log file.
localhost_access_log. txt tomcat records user access information, indicating time.
For example: localhost_access_log.2016-02-28.txt
temp: Temporary file directory, the contents of the folder can be deleted arbitrarily.
webapps: The directory where the WEB project is published by default.
work: The working directory where tomcat handles JSPs.
Launch and access
tomcat decompression directory /bin/startup.bat Double-click to start tomcat
access path: http://localhost:8080/
web project
In the JavaEE specification, the WEB project has a certain directory structure, the specific structure is as follows:
项目名称
|-----静态资源.HTML,CSS,JS
|-----WEB-INF
|----web.xml 当前WEB项目的核心配置,Servlet2.5必须有,3.0可省略。
|----lib 当前WEB项目所需要的第三方的jar的存放位置。
|----classes Java源码编译后生成class文件存放的位置。
Publish web projects through eclipse
Configure Tomcat
- Step 1: Eclipse obtains the server runtime environment configuration, Window/Preferences/Server/Runtime Environment
- add server
- Select the address of the server on the hard disk, then all is OK/Next/Finish
- Complete server addition
- Set publish location
There are three options (marked as above):
A. Using the eclipse workspace, taking the above example as D:\workSpace.metadata.plugins\org.eclipse.wst.server.core\tmp0
B. Using tomcat installation Directory, taking the above example as C:\dev_soft\apache-tomcat-9.0.2
C. Custom path, here is the directory of your own choice
You can also define which directory in the container the project is deployed to by modifying the Deploy path. For example, in the figure below, we can choose the Use Tomcat Installtion method, and set the Deploy path to webapps, and press ctrl + s to save.
Publish web project
- Right-click on the project/Run As/Run on Server
- Select the WEB server to execute the program
- Add or delete java projects to the web server