0

我有一个非常简单的 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。

我将战争文件部署到 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”。

4

2 回答 2

1

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

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

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

于 2017-01-27T16:40:43.253 回答
0

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

于 2014-11-04T05:54:38.467 回答