Tomcat installation, deployment and integration with IDEA to create Web projects
number_one: official website download
1.1 Select version: Tomcat 8
1.2. Select the number of download bits (choose according to the number of computer bits)
number_two: tomcat installation and uninstallation
2.1. Select the path, unzip it and the installation is complete.
2.2. Delete the corresponding folder and the uninstallation is complete.
number_three: tomcat startup and access
3.1. windows: double-click startup.bat in the bin directory
3.2. linux: Double-click startup.bat in the bin directory
3.3. Do not shut down after startup
3.4. Local access: 127.0.0.1:8080
3.5. You can also use: localhost:8080
3.6. Access by others: need to know the ip address of the machine, check method: win + r, enter cmd, enter command: ipconfig + enter
3.7. Problems that may be encountered:
a. 黑窗口一闪而过:
原因:没有正确配置JAVA_HOME环境变量
解决方案:正确配置JAVA_HOME环境变量
b.启动报错:
原因:端口号被占用
解决方案:
1. 暴力(推荐):找到占用的端口号,并找到对应的进程,杀死该进程
cmd --> netstat -ano
2. 温柔:修改自身端口号
文件:bin/ conf/ server.xml
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
一般会将tomact的默认端口号修改为80,80端口号是http协议的默认端口号,
这样在访问时就不用输入端口号,直接:http://ip + 回车
3.7.1. Violently close the port number process (recommended): find the occupied port number, and find the corresponding process, kill the process
cmd --> netstat -ano
3.7.2. win + x, -> Task Manager- -> Details --> PID sorting, end the process
number_four: off
4.1. 正常关闭
bin/ shutdown.bat
ctrl + c
4.2. 强制关闭
点击启动窗口的 x
number_five: 3 ways to configure and deploy the project
5.1. (开发者会即可)直接将项目放到 webapps 目录下即可
/hello:项目的访问路径 -->虚拟路径
简化部署:将项目打包成一个 war 包(方式1:专门war打包工具;方式2:可以将 .html 直接压缩成 .zip 文件,修改后缀为 .war),再将 war 包放置到 webapps 目录下, war 包会自动解压缩。
5.2. (方式3是对2的优化,所以一般不推荐2)配置 conf/ server.xml 文件
在<Host>标签体中配置
<!-- 配置项目 dacBase:项目存放路径 path:虚拟目录-->
<Context docBase="D:\hello" path="/hehe" />
5.3. (运维人员推荐)在 conf\Catalina\localhost 创建任意名称的 .xml 文件,在文件中编写:
<Context docBase="D:\hello" />
虚拟目录:.xml 文件的名称
Method 2 (not recommended)
Method 3 ( recommended by operation and maintenance personnel)
number_six: Tomcat and IDEA integration, create a Web project
6.1: Directory structure of static projects and dynamic projects:
java动态项目的目录结构
-- 项目的根目录
-- WEB-INF目录
-- web.xml:web项目的核心配置文件
-- classes目录:仿真放置字节码文件的目录
-- lib目录:放置依赖的jar包
6.2: Integrate Tomcat into IDEA, create JavaEE projects, and deploy projects.
Note: IDEA community version is not supported. It is recommended to use the ultimate version for professionals. Download URL: https://www.jetbrains.com/idea/download/ other.html
6.3: Integration of Tomcat and IDEA
6.4: Some Tomcat configurations
6.5: New Web Project
6.6: Create a new hello.html file in the Web directory
6.7: The browser test is successful
This concludes this section