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 ?
You would normally use the
<welcome-file>entry in theweb.xmlfor 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 aFacesServlet. 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.xhtmlas<welcome-file>is also not going to work since that page requires to be parsed by theFacesServletto get all the JSF stuff to work.One of the ways to fix this is to place another real
/foobar.facesfile there next to the real/foobar.xhtmlfile. 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.