【问题标题】:How do I display an HTML file using Websphere Liberty?如何使用 Websphere Liberty 显示 HTML 文件?
【发布时间】:2015-02-02 23:49:24
【问题描述】:

我有静态 HTML 页面。我使用 Apache 服务器(通过 XAMPP)将我的 HTML 文件放在 htdocs 文件夹中,并且可以通过 localhost 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> 

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

【问题讨论】:

    标签: html apache websphere-liberty static-content


    【解决方案1】:

    最简单的:

    • dropins文件夹(\wlp\usr\servers\serverName\dropins)中,创建文件夹myApp.war
    • 将您的index.html 放入myApp.war

    如果您的服务器配置为轮询监控,您就完成了。否则重新启动服务器(如果已启动)。
    它将通过http://host:port/myApp/index.html 提供。

    【讨论】:

      【解决方案2】:

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

      + 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,您需要以下网址:

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

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

      Handling Static Content in WebSphere Application Server

      【讨论】:

      • 为了使事情更简单,您实际上不必创建存档 (zip/war),而只需创建以“.war”后缀命名的文件夹,例如“SampleHTMLSite.war”。战争”
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-02-03
      • 1970-01-01
      • 1970-01-01
      • 2016-05-30
      • 1970-01-01
      • 2017-05-16
      • 1970-01-01
      相关资源
      最近更新 更多