我有一个在Tomcat 8上运行的java Web应用程序。在 localhost:8080
上运行的应用程序。我想做的是,将一个额外的 html 文件部署到 tomcat 并使其在 localhost:8080/path
下运行。我该怎么做?
一种解决方案是简单地在上下文路径上部署一个简单的新 Web 应用程序,/path
仅提供该 html 文件。这样,您无需接触现有的ROOT
应用程序:
创建一个apache-tomcat/webApps/path/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_3_1.xsd"
version="3.1"
metadata-complete="true">
<display-name>Additional HTML File</display-name>
<description>
Additional HTML File
</description>
</web-app>
创建一个 apache-tomcat/webApps/path/index.html:
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<h1>Additional HTML File!!!2</h1>
</body>
</html>
启动雄猫并访问 http://localhost:8080/path
这将向您显示索引.html文件。