开发者

JSF: make A.jsf a default page to go to when type mydomain.com

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

<welcome-file-list>
    <welcome-file>CentralFeed.jsf</welcome-file>
</welcome-file-list>          
<login-config>
    <auth-method>FORM</auth-method>
    <realm-name>jdbc-realm-scholar</realm-name>
    <form-login-config>
        <form-login-page>/home.jsf</form-login-page>
        <form-error-page>/LoginError.jsf</form-error-page>
    </form-login-config>
</login-config>
 <filter>
    <filter-name>MyFilter</filter-name>
    <filter-class>com.scholar.servlet.MyFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>MyFilter</filter-name>
    <url-pattern>/CentralFeed.jsf</url-pattern>     开发者_开发技巧   
    <url-pattern>/TextBook.jsf</url-pattern>
    ...
</filter-mapping> 

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


put index.jsp

and in it put

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

remove

<welcome-file-list>
    <welcome-file>CentralFeed.jsf</welcome-file>
</welcome-file-list>    

from web.xml


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜