【问题标题】:Glassfish server welcome-file not working?Glassfish 服务器欢迎文件不起作用?
【发布时间】:2014-11-03 15:15:06
【问题描述】:

我有一个非常简单的 web.xml 文件:

<?xml version="1.0" encoding="UTF-8" ?>
<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">
    <welcome-file-list>
        <welcome-file>abcd.jsp</welcome-file>
    </welcome-file-list>
    <context-param>
        <param-name>foo</param-name>
        <param-value>bar</param-value>
    </context-param>
</web-app>

我的应用程序中有 2 个 jsp 文件 hello.jsp 和 abcd.jsp。

我将war文件部署到Glassfish服务器,上下文根是“novone”

当我转到 localhost:8080/novone 时,我看到的是 hello.jsp,而不是 abcd.jsp...

在 Glassfish 管理面板(local4848/common/index.jsf) Applications->novone->Descriptor->Description-File 我看到了:

<?xml version="1.0" encoding="UTF-8" ?>
<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">
    <welcome-file-list>
        <welcome-file>abcd.jsp</welcome-file>
    </welcome-file-list>
    <context-param>
        <param-name>foo</param-name>
        <param-value>bar</param-value>
    </context-param>
</web-app> 

为什么提供 hello.jsp 而不是 abcd.jsp?

当我手动转到 /novone/abcd.jsp 时,我可以看到从应用程序范围加载的值“bar”。

【问题讨论】:

  • 哪个版本的 Glassfish?
  • @unwichtich 4.1版

标签: java jsp glassfish welcome-file


【解决方案1】:

这不是很明显,但是我发现如果你让 IntelliJ 自动生成 war 文件,如果你进入 Project Structure > Facets,你会在 Web 下看到右上角有一个 Web Module Deployment Descriptor ,以及右下角的一个 Web 资源目录。

如果您在底部框架中突出显示该 Web 资源目录,您将看到 Web 资源目录可能默认设置为 /web 作为根。

您可以点击编辑图标并将其更新为 / 然后您的欢迎文件应该可以工作,因为它将在您的网络资源中被考虑。

【讨论】:

    【解决方案2】:

    您的 GlassFish 设置似乎没有任何问题。您清除浏览器缓存并重试或在其他浏览器中尝试。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-10-06
      • 2021-02-12
      • 2012-05-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-03
      相关资源
      最近更新 更多