问题
I have "/pages/index.xhtml" page. The problem is when i run the application, this index page name doesn't appears at address bar.
It only shows http://localhost:8080/myApplication/
. What I want to see is http://localhost:8080/myApplication/pages/index.xhtml
Is there any solution?
here is my welcome file from web.xml
<welcome-file-list>
<welcome-file>pages/index.xhtml</welcome-file>
</welcome-file-list>
回答1:
You need to send a redirect from /
to /pages/index.xhtml
. Easiest is to use a real index file with a meta refresh header for this.
First create a /index.xhtml
file as follows:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Dummy homepage</title>
<meta http-equiv="refresh" content="0; url=pages/index.xhtml" />
</head>
</html>
Then change your <welcome-file>
as follows:
<welcome-file>index.xhtml</welcome-file>
This also instantly fixes your bad way of using <welcome-file>
. It's not supposed to specify the "home page", but it's supposed to specify the folder's own file which needs to be served when a folder such as /
or /foo/
is requested in URL instead of a file.
See also
- How to use a sub-folder as web.xml welcome directory
- why do i get the protected page instead of the login page?
来源:https://stackoverflow.com/questions/17047451/how-to-show-full-page-url-of-welcome-file-in-address-bar