[英]web.xml welcome-file with subfolders
假设我在项目中具有以下文件夹结构:
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>
我希望web.xml欢迎文件始终指向index.xhtml文件,但是如果我调用http://webappname/admin/
,服务器将尝试调用http://webappname/admin/index.xhtml
而不是http://webappname/index.xhtml
因此,我尝试使用/作为第一个字符,以在根文件夹中进行搜索。 web.xml看起来像这样:
<welcome-file-list>
<welcome-file>/login.xhtml</welcome-file>
</welcome-file-list>
但是现在它搜索http://webappname//admin//login.xhtml
如何调用根文件夹中的文件? 没有解决方案吗? 我是否必须在每个文件夹中放置重定向才能获得结果?
如果URL中仅提供一个文件夹,则默认行为是AFAIK寻找文件index.xxx
(xxx是容器特定的扩展名,xhtml,视情况而定)。 如果用户没有提供应访问该应用程序的更多信息,则将使用欢迎文件。
因此, http://webappname/
应该解析为欢迎文件,而http://webappname/admin/
将解析为admin/index.xhtml
。
您可以使用全局重写将用户重定向到欢迎文件,方法是使用外部Web服务器(例如带有mod_rewrite的Apache)或内部URL重写(例如Tuckey URL Rewriting库) 。
顺便说一句,由于您的欢迎文件名为login.xhtml
,当用户login.xhtml
,是否应该始终将其重定向?
您还需要将login.html
保留在admin
目录中。由于您正在使用http://webappname/admin/
请求admin目录,因此服务器首先尝试在admin目录中检查指定的欢迎文件。
This happen because "welcome-file" is internally implemented to fetch from the user requested directory level instead of Web application directory level.
注意:
欢迎文件值不能以斜杠开头或结尾,并且将按照在部署描述符中出现的顺序来选择它们
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.