【问题标题】:Access HTML within WAR file访问 WAR 文件中的 HTML
【发布时间】:2016-03-25 15:08:38
【问题描述】:

我无法从我的 .war 文件访问我的 index.html。我将 index.html 放在根 war 文件路径中。这也是 META-INF 和 WEB-INF 文件夹所在的位置。当我尝试从我的网址http://localhost:8080/Test/index.html 访问它时,我得到了

“JBWEB000065:HTTP 状态 404 - 找不到相对资源:/index.html of full path: http://localhost:8080/Test/index.html

在我的 server.log 上,我看到服务器成功启动,没有任何错误。此外,当我尝试访问该页面时,我没有在 server.log 上获得任何堆栈跟踪。我还在 war 文件中构建了一个 Web 服务,当我测试 RESTful 服务 (http://localhost:8080/Test/Query?key=Hello%20World) 时,我得到了成功的响应。

我做错了什么无法访问网页?

【问题讨论】:

    标签: rest war soa jboss-eap-6


    【解决方案1】:

    “Could not find resource for relative : /index.html”表示您的应用正在尝试将 index.html 挖掘为 RESTful 资源而不是静态文件。

    没有看到您的 web.xml,我猜您有一个处理所有 URL 模式的 <servlet-mapping> 条目;像这样:

    <servlet-mapping>
      <servlet-name>My RESTful servlet</servlet-name>
      <url-pattern>/*</url-pattern>
    </servlet-mapping>
    

    为了解决这个问题,this SO 看起来很有帮助,它实质上建议在您的资源路径中添加一个额外的令牌,例如:

    <url-pattern>/service/*</url-pattern>
    

    这意味着您必须以http://localhost:8080/Test/service/Query?key=Hello%20World 的身份访问您的查询资源。

    【讨论】:

      猜你喜欢
      • 2020-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-03
      • 2012-06-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多