views:

37

answers:

2

I have written a facelets web application using tomcat as a application server. My program has a foobar.xhtml and the URL to it is:

http://localhost:8080/Myapplication/foobar.faces

Can I change something in my application so that a link to:

http://localhost:8080/Myapplication/

..will actually render my application on http://localhost:8080/Myapplication/foobar.faces ?

Alternatively, could the http://localhost:8080/Myapplication/ be redirected to http://localhost:8080/Myapplication/foobar.faces ?

A: 

web.xml has a

<welcome-file-list>
    <welcome-file>foobar.faces</welcome-file>
</welcome-file-list>

element where you can define the page to be opened.

MCA
+1  A: 

You would normally use the <welcome-file> entry in the web.xml for this. But unfortunately this doesn't work as expected on at least Tomcat when using fictive URL's which are to be passed through a servlet like a FacesServlet. Tomcat will scan for the physical file on the disk matching the exact name before forwarding. If it isn't present, then you will just face a default 404 error page.

Using /foobar.xhtml as <welcome-file> is also not going to work since that page requires to be parsed by the FacesServlet to get all the JSF stuff to work.

One of the ways to fix this is to place another real /foobar.faces file there next to the real /foobar.xhtml file. It doesn't need to be filled with code, it can be left empty. Just the presence of the physical file is enough for Tomcat to open the desired page as welcome page.

BalusC
Thanks! I've tried the welcome-file-list before but it didn't work. Now I understand it is a tomcat issue. Great to have it solved.
Roalt