Welcome pages in java ee 6

跟風遠走 提交于 2020-01-07 04:08:04

问题


As a follow up to this question, can one specify the welcome pages without web.xml? If possible, how? If not possible, are welcome pages simply not used? If not used, what are the advantages and disadvantages?


回答1:


You can specify the welcome page without declare in web.xml. You use some html file and forward to your desire start page.see sample,

index.jsp

  <html>
  <body>
  <jsp:forward page="/pages/welcome.jsf" />
  </body>
  </html>

The index.jsp page forward to welcome.jsf page without declare to welcome-file-list tag in your web.xml.

Advantages of using welcome-file-list

When the URL request is a directory name, Application Server serves the first file specified in welcome-file-list element.

Disadvantages of without using welcome-file-list

If that welcome-file-list is not found, the server then tries the next file in the web.xml.Its taken more time and 404 error may be found.




回答2:


The welcome files mechanism allows you to specify a list of files that the web container will use for appending to a request for a URL (called a valid partial request) that is not mapped to a web component.(from link)
Why don't you use a web.xml file ?

If you really don't want to use a web.xml file, then you could use a Filter to forward a request to your welcome page.

Update: The web container should have a welcome file list of its own. For example Tomcat has a web.xml file in its conf folder. It has

<welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>


来源:https://stackoverflow.com/questions/11788053/welcome-pages-in-java-ee-6

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