登录后如何重定向? [英] How to redirect after login?

查看:155
本文介绍了登录后如何重定向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将用户名和密码绑定到后备托管bean. 在备用Bean中,当我使用DB检查用户名和密码时,我想将页面从login.xhtml重定向到home.xhtml.我该怎么办?

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?

推荐答案

只需返回附加了faces-redirect=true参数的视图ID.

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

例如

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).
    }
}

这篇关于登录后如何重定向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆