How to redirect after login?

筅森魡賤 提交于 2019-12-31 05:04:06

问题


I've username and password bound to the backing managed bean. In the backing bean, when I check the username and password with DB, I want to redirect the page from login.xhtml to home.xhtml. How can I do that?


回答1:


Just return the view ID appended with faces-redirect=true parameter.

E.g.

public String login() {
    User found = userService.find(username, password);

    if (found != null) {
        this.user = found;
        return "home?faces-redirect=true"; // Will redirect to home.xhtml.
    }
    else {
        addGlobalErrorMessage("Unknown login, please try again");
        return null; // Will stay in current view (and show error message).
    }
}


来源:https://stackoverflow.com/questions/10671950/how-to-redirect-after-login

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!