Eva
Eva

Reputation: 4690

Welcome pages in java ee 6

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?

Upvotes: 0

Views: 1974

Answers (2)

Sai Ye Yan Naing Aye
Sai Ye Yan Naing Aye

Reputation: 6738

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.

Upvotes: 2

rickz
rickz

Reputation: 4474

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>

Upvotes: 1

Related Questions