Assuming I have the following folder structure in a project:
webapp
|-admin
|--adminfile1.xhtml
|--adminfile2.xhtml
|-user
|--userfile1.xhtml
|--userfile2.xhtml
|login.xhtml
in my web.xml I have this definition for the welcome-file
<welcome-file-list>
<welcome-file>login.xhtml</welcome-file>
</welcome-file-list>
I want the web.xml welcome file to always point at the index.xhtml file, but if I call http://webappname/admin/
the server tries to call http://webappname/admin/index.xhtml
instead of http://webappname/index.xhtml
so I tried it with a / for the first char, to search in the root folder. The web.xml looks like this:
<welcome-file-list>
<welcome-file>/login.xhtml</welcome-file>
</welcome-file-list>
But now it searches for http://webappname//admin//login.xhtml
How can I call the file in the root folder? Isn't there a solution for doing this? Do I have to put redirects in every folder to get my result?
AFAIK looking for a file index.xxx
(xxx being a container specific extension, xhtml i your case) is default behavior if just a folder is provided in the url. The welcome file would be used if the user didn't provide any further information than that the application should be accessed.
Thus http://webappname/
should resolve to the welcome file while http://webappname/admin/
would resolve to admin/index.xhtml
.
You could use a global rewriting to redirect the user to the welcome file, either by using an external webserver like Apache with mod_rewrite or an internal url rewriting like the Tuckey URL Rewriting library .
Btw, since your welcome file is called login.xhtml
, shouldn't the user always be redirected when she's not logged in?
You need to keep login.html
in admin
directory also.Since you are requesting admin directory using http://webappname/admin/
.With this request,server first try to check the specified welcome file in admin directory.
This happen because "welcome-file" is internally implemented to fetch from the user requested directory level instead of Web application directory level.
Note:
A welcome-file value cannot start or end with a slash, and they will be picked in the order they appear in the deployment descriptor
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.