How to show full page URL of welcome file in address bar

对着背影说爱祢 提交于 2019-12-12 18:58:00

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!