Search code examples
http-redirectjsf-2glassfish

redirecting pages to one JSF index


I have a jsf app which has an index page as default, configured on web.xml:

    <welcome-file-list>
        <welcome-file>faces/index.xhtml</welcome-file>
    </welcome-file-list>

So, if I navigate to the address http://myIp:8080/myContext/ it redirects automatically to the address http://myIp:8080/myContext/faces/index.xhtml

I want to use this address in a way which allows the user to insert any text after the context address and the server automatically redirects to desired index, configured on welcome-file-list.

Some input examples that I want to redirect directly to my index page

http://myIp:8080/myContext/blahblahblah

http://myIp:8080/myContext/blahblahblah.jpg

http://myIp:8080/myContext/ (this is the only one working actually)

Obs.: I'm using glassfish, if the web container matters


Solution

  • As proposed by @xtreme-biker, I used the 404 error to trigger the index page.

    This is the code I added to the web.xml Thus, any address I insert in the browser, it redirects me to the index page.

    <error-page>
        <error-code>404</error-code>
        <location>faces/index.xhtml</location>
    </error-page>