html - 如何使用 Websphere Liberty 显示 HTML 文件?

标签 html apache websphere-liberty static-content

我有静态 HTML 页面。使用 Apache 服务器(通过 XAMPP)我曾经将我的 HTML 文件放在 htdocs 文件夹中,并且可以通过本地主机 URL 访问它们。

我不确定如何使用 Websphere Liberty 服务器执行此操作。假设我在 index.html

中有以下 HellWorld HTML 示例
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>HellWorld</title>
  </head>    
  <body>
    <p>HellWorld</p>
  </body>
</html> 

如何通过 Liberty 让这个 HTML 页面显示在浏览器中?

最佳答案

所需的最小文件夹结构如下

+ SampleHTMLSite.war
  - index.html

要创建 .war 文件,只需压缩您的 index.html 文件,然后将压缩文件夹的扩展名从 .zip 更改为.war

如果您通过 server run 命令在前台运行 Liberty 服务器,只要您将此网站放入 Liberty 的 dropins 文件夹(通常位于此处:. ..\wlp\usr\servers\YourServerName\dropins) 你会得到类似下面的更新:

[AUDIT   ] CWWKT0016I: Web application available (default_host): 
           http://localhost:9080/SampleHTMLSite/
[AUDIT   ] CWWKZ0001I: Application SampleHTMLSite started in 0.317 seconds.

如果您转到 http://localhost:9080/SampleHTMLSite/index.html,您应该能够看到您的 HelloWorld HTML 页面。

如果出现以下错误:

Error 404: java.io.FileNotFoundException: SRVE0190E: File not found: /index.html 

用任何解压缩程序(例如:7-Zip)打开您的 SampleHTMLSite.war 并确保 index.html 直接显示在 .war 文件中,并且不在另一个文件夹中。您有可能具有以下结构:

+ SampleHTMLSite.war
  + SampleHTMLSite
    - index.html

这意味着要访问 index.html,您需要以下 URL:

http://localhost:9080/SampleHTMLSite/SampleHTMLSite/index.html

在更大的项目中以及您需要使用 Java 应用程序的地方,您的文件夹结构可能需要包含其他文件夹和文件。如果您有兴趣了解更多相关信息,请查看以下文章:

Handling Static Content in WebSphere Application Server

关于html - 如何使用 Websphere Liberty 显示 HTML 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27305207/

相关文章:

http - 如何在 WebSphere Liberty 中为 SOAP 客户端设置 HTTP 基本身份验证

java - Liberty 提供哪些日志记录 API?

html - Chromium 是否兼容 HTML5?

javascript - Jquery和localStorage如何向网站clipdoard/cart添加更多元素

php - Whatsmyip 从 file_get_contents 中提供的 IP 与浏览器中的 IP 不同

java - Apache Tomcat 8.5.9 中未设置 X-Frame-Options header

java - 我们如何在 Liberty Server 中配置 DataSource 以实现 native 连接

javascript - 图像未立即加载

javascript - 使用 jquery 添加不适用于 html5 视频播放器的类

apache - 相对路径的 SSL?