web-services - 如何在 Tomcat 8 中部署 HTML 文件和 Web 应用程序?
问题描述
我有一个在 Tomcat 8 上运行的 Java Web 应用程序。该应用程序在localhost:8080
. 我想要做的是,将一个额外的 html 文件部署到 tomcat 并使其在localhost:8080/path
. 我怎样才能做到这一点?
解决方案
/path
一种解决方案是在仅服务于该 html 文件的上下文路径上简单地部署一个简单的新 Web 应用程序。这样您就不需要接触现有的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>
启动tomcat,访问http://localhost:8080/path
这将显示 index.html 文件。
推荐阅读
- html - 内容溢出容器并在屏幕缩小时重叠页脚
- postgresql - PostgreSQL 未用于我们数据库的表,查询问题?
- git - 将 repo 移动到新的分支/repo
- r - 是否可以在 R 中仅显示带有 ggplot 的特定刻度线?
- python - 使用 Ironclad 在 Iron Python 中实现 Opencv
- python - 从 GitHub (urllib.request) 下载 csv 文件时出错
- linux - x86 中的分段与 linux 下编译器中的分段
- testing - 如何在 Azure DevOps 中运行未完成时更改其状态
- asp.net-core - 尝试激活“XXXXX”时无法解析“Microsoft.AspNetCore.SignalR.Hub`1[IXXXX]”类型的服务
- java - 使用attributeconverter时,SpringBoot应用程序未完成启动