Take the 2-minute tour ×

Right now, every time I type mydomain.com it would automatically go to mydomain.com/projectname/home.jsf, which is my login page. Not sure why, I know I still in session meaning that I can navigate to a restricted page without login in again. So how do I make so that if I type mydomain.com, I go to mydomain.com/projectname/CentralFeed.jsf instead of login page if the user still in session. Here is my rough design

In my web.xml


I am not sure if you guys need to know this, but I also have a Filter call MyFilter, which map to restricted page, and check if the user still in session, if so then just chain.doFilter(req, res);, if not then redirect to login page home.jsf

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

put index.jsp

and in it put

<% response.sendRedirect("desired URL"); %>



from web.xml

share|improve this answer
Does that work for jsf as well? –  Thang Pham Mar 17 '11 at 17:57
yes. by response.sendRedirect() you will just make client to GET desired URL which you want to redirect from root –  Jigar Joshi Mar 17 '11 at 17:58
I hope you dont mind if I ask this, so CentralFeed.jsf is the page I want to always go first. If I change that page to index.jsf, will I get the same result, like what you suggest above? –  Thang Pham Mar 17 '11 at 18:04
yes. but go for the approach I have suggested –  Jigar Joshi Mar 17 '11 at 18:06
Dont think it work: Here is my Exception: javax.servlet.ServletException: Error Parsing /index.xhtml: Error Traced[line: 12] The content of elements must consist of well-formed character data or markup. I am using JSF Facelets btw –  Thang Pham Mar 17 '11 at 18:13
show 2 more comments

The <welcome-file> has to point to a physical file on the disk, not to some servlet mapping. Since you've a CentralFeed.xhtml file, a <welcome-file> of CentralFeed.jsf isn't going to work.

There are two solutions (apart from the scriptlet hack as suggested by Jigar):

  1. Create an empty file CentralFeed.jsf file next to the CentralFeed.xhtml. This fools the server that the file is physically present.

  2. Map the FacesServlet on *.xhtml instead of *.jsf. While this was impossible in JSF 1.x because it would run in an infinite loop, this works fine on JSF 2.0. Your question history confirms that you're using JSF 2.0. This way you can just set the <welcome-file> to CentralFeed.xhtml.

share|improve this answer
Thank you so much for the great information. Learn something new :D –  Thang Pham Mar 18 '11 at 1:03
add comment

Your Answer


