Search code examples
jsfjakarta-eeglassfishglassfish-3

glassfish: redirect all url to index


I'm working on the java ee application using glassfish 3 server and jsf. I want all of requests to urls starting from my context root to be redirected to my index.xhtml. For example, if a user types: my-host/my-app-context-root/lgsfdjglksjdflgjldskfjg-anything I want this request to be redirected to: my-host/my-app-context-root/index.xhtml

So I want to know how can I implement this rule. If it's possible, I would like to do it somehow using Java/jsf or web.xml or some other files which belongs to my application only. I want to avoid to do any "general" server configurations, such as setting properties "redirect_n" as it is suggested there.

Thanks in advance and sorry for my English.


Solution

  • You could create a servlet filter with mapping "/*". Then use HttpServletRequest#getRequestURI() to check whether this is a request for js/css files or any other request and you can accordingly redirect to index.xhtml.