开发者

Remove Foobar.xhtml from URL with JSF

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://l开发者_运维技巧ocalhost:8080/Myapplication/ be redirected to http://localhost:8080/Myapplication/foobar.faces ?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜