问题
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