How to redirect after login?

前端 未结 1 531
既然无缘
既然无缘 2021-01-24 08:23

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.

相关标签:
1条回答
  • 2021-01-24 08:56

    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).
        }
    }
    
    0 讨论(0)
提交回复
热议问题