开发者

jsf auto-login according to cookie

I'm having a problem in achieving an auto-login feature for my JSF application which is being proted from a JSP & servlet-based architecture.

I used LoginBean backing the jsf pa开发者_Go百科ge with a constructor method to check if the cookie containing the user crendtials exists, and if it does to automatically open a session and redirect the user to the main page.

The auto-login never takes place and the user always remains in front of the login form. What should I do to make it work?


Here is an option that should work. You can do something like this once you've ascertained that they are valid:

final ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();

try {
    HttpServletResponse response = (HttpServletResponse) externalContext.getResponse();

    if (!response.isCommitted()) {
        externalContext.redirect("loggedin.xhtml");
    }
} catch (IOException ex) {
    // log etc.
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜