Java 包含子文件夹的web.xml欢迎文件

Java 包含子文件夹的web.xml欢迎文件,java,jsf,jakarta-ee,web.xml,Java,Jsf,Jakarta Ee,Web.xml,假设我在项目中具有以下文件夹结构: webapp |-admin |--adminfile1.xhtml |--adminfile2.xhtml |-user |--userfile1.xhtml |--userfile2.xhtml |login.xhtml 在我的web.xml中,我对欢迎文件有这样的定义 <welcome-file-list> <welcome-file>login.xhtml</welcome-file> </welco

假设我在项目中具有以下文件夹结构:

webapp
|-admin
|--adminfile1.xhtml
|--adminfile2.xhtml
|-user
|--userfile1.xhtml
|--userfile2.xhtml
|login.xhtml
在我的web.xml中,我对欢迎文件有这样的定义

<welcome-file-list>
    <welcome-file>login.xhtml</welcome-file>
</welcome-file-list>
但现在它搜索
http://webappname//admin//login.xhtml


如何调用根文件夹中的文件?这样做难道没有解决办法吗?我是否必须在每个文件夹中放置重定向才能获得结果?

AFAIK查找文件
索引。如果url中只提供了一个文件夹,则默认行为为xxx
(xxx是特定于容器的扩展名,xhtml I您的情况下)。如果用户没有提供除应访问应用程序之外的任何其他信息,则将使用欢迎文件

因此
http://webappname/
应解析为欢迎文件,而
http://webappname/admin/
将解析为
admin/index.xhtml

您可以使用全局重写将用户重定向到欢迎文件,可以使用外部Web服务器(如Apache with mod_rewrite)或内部url重写(如)


顺便说一句,由于您的欢迎文件名为
login.xhtml
,用户未登录时不应该总是重定向吗?

您还需要将
login.html
保存在
admin
目录中。因为您使用
http://webappname/admin/
。根据此请求,服务器首先尝试检查管理目录中指定的欢迎文件。
This happen because "welcome-file" is internally implemented to fetch from the user requested directory level instead of Web application directory level. 之所以会出现这种情况,是因为“欢迎文件”是在内部实现来获取的 从用户请求的目录级别而不是Web应用程序目录级别

注:

欢迎文件值不能以斜杠开头或结尾,它们将按照它们在部署描述符中出现的顺序拾取


是的,他们应该。我有一个过滤器来做这个 This happen because "welcome-file" is internally implemented to fetch from the user requested directory level instead of Web application directory level.