如何将子文件夹用作web.xml欢迎目录

8

我希望配置我的Google App Engine的web.xml文件,但是我的配置不起作用。我想将默认的index.html更改为WebApp/index.html

这是我的web.xml文件:

<servlet>
    <servlet-name>App</servlet-name>
    <servlet-class>bg.app.AppServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>App</servlet-name>
    <url-pattern>/WebApp/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
    <welcome-file>WebApp/index.html</welcome-file>
</welcome-file-list>

我不知道你所说的“配置不起作用”的意思,但是<welcome-file-list>声明需要放在<servlet>元素之前。 - Sotirios Delimanolis
4
@SotiriosDelimanolis 不会的 ;)。 - uccie
1个回答

16

"欢迎文件"代表URL请求文件夹时需要提供的物理文件。例如://WebApp/WebApp/foo/。它并不代表"主页文件",许多初始用户似乎会这样想。将欢迎文件指向子文件夹是没有意义的,因为当请求另一个子文件夹时,它将失败。

只需将index.html作为欢迎文件,将所需的主页文件放入/WebApp/文件夹中,并在根目录/中创建另一个index.html文件,内容如下:

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Dummy homepage</title>
    <meta http-equiv="refresh" content="0; url=WebApp" />
  </head>
</html>

这将重定向到/WebApp/(搜索引擎会将其视为301),然后应该提供所需的主页文件。

另请参阅:


1
这个功能非常好用,相比于welcome-file-list的优势在于地址栏中的URL实际上会更改为上面meta标签中指定的内容。 - Russ Jackson

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接