Tomcat
Tomcat
下载
Apache Tomcat® - Apache Tomcat 9 Software Downloads
安装
解压,将文件夹移动到自己想要的路径
环境变量配置(不是必须的,配置只是为了命令行可以直接执行startup.bat等脚本)
环境变量->系统变量->新建
变量名CATALINA_HOME 变量值path\to\apache-tomcat-9.0.100
Path变量新增项:%CATALINA_HOME%\bin
Tomcat配置
conf/server.xml
<!-- 端口配置(默认为8080)、协议、超时时长、重定向端口、最大参数数量 -->
<Connector port="8099" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
maxParameterCount="1000"
/>
<!-- 默认绑定主机名、应用所在目录、是否解包war、是否自动部署 -->
<!-- 此处的主机名需要与主机中定义的主机名一致,例如windows下 C:\Windows\System32\drivers\etc\hosts 文件中设置的主机名 -->
<!-- 修改如下 -->
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
127.0.0.1 ssydx
<!-- 此时该处的name也应设置为ssydx -->
<Host name="ssydx" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<!-- 最终本地访问为ssydx:8099 -->
webapps/ROOT/index.jsp
<!-- 未添加应用是默认访问ROOT应用、index.jsp就是其主页 -->
发布应用
复制一份ROOT修改名称,删除除WEB-INF之外的内容
/webapps/webappname/WEB-INF/web.xml
<!-- 里面可进行应用的设置 -->
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0"
metadata-complete="true">
</web-app>
新建/webapps/webappname/index.html
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>SSYDX</title>
</head>
<body>
<h1>这是首页</h1>
<p>Hello world</p>
<a href="./other.html">去另一页</a>
</body>
</html>
新建/webapps/webappname/other.html
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>SSYDX</title>
</head>
<body>
<h1>这是另一页</h1>
<p>Hello ssydx</p>
<a href="./index.html">去首页</a>
</body>
</html>
启动Tomcat
双击执行/bin/startup.bat或/bin/startup.sh
在浏览器输入localhost:8099会访问ROOT应用
在浏览器输入localhost:8099/webappname会访问webappname应用
默认显示的是index页面
其他文件夹
examples | 一些应用样例 |
host-manager | 主机管理,提供可视化界面进行设置,需要设置用户信息,在/conf/tomcat-users.xml文件中 |
manager | 应用管理,提供可视化界面进行设置,需要设置用户信息,在/conf/tomcat-users.xml文件中 |
docs | tomcat的帮助文档 |