java 登录后 JSF 2.0 重定向到 index.jsf

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15134340/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 18:36:12  来源:igfitidea点击:

JSF 2.0 redirect to index.jsf after login

javajsf-2jboss6.xjaas

提问by mbulau

We have a JSF (2.0) based web application, running on JBoss 6.1. We are using the FORM based authentication with JAAS.

我们有一个基于 JSF (2.0) 的 Web 应用程序,在 JBoss 6.1 上运行。我们在 JAAS 中使用基于 FORM 的身份验证。

Some of the users adding links like this "admin/editUser.jsf" to their bookmarks. This page don't work correctly if the user access this page directly (without using the navigation within the application).

一些用户将像“admin/editUser.jsf”这样的链接添加到他们的书签中。如果用户直接访问此页面(不使用应用程序中的导航),则此页面无法正常工作。

The question is: is there any way to redirect the user to the index.jsf page after login, independent from the requested url?

问题是:有没有什么方法可以在登录后将用户重定向到 index.jsf 页面,独立于请求的 url?

回答by BalusC

That's not possible.

那是不可能的。

If you're on Servlet 3.0 (Tomcat 7 / Glassfish 3 / JBoss 6 / etc), then your best bet is to use programmatic login with HttpServletRequest#login()instead of a JAAS form.

如果您使用的是 Servlet 3.0(Tomcat 7 / Glassfish 3 / JBoss 6 / 等),那么最好的办法是使用程序化登录HttpServletRequest#login()而不是 JAAS 表单。

So, instead of

所以,而不是

<form action="j_security_check" method="post">
    ...
    <input type="submit" />
</form>

use

利用

<h:form>
    ...
    <h:commandButton value="Login" action="#{bean.login}" />
</h:form>

with

public String login() {
    // ...

    request.login(username, password);

    // ...

    return "index.jsf?faces-redirect=true";
}

See also:

也可以看看:

回答by puchmu

You can use a navigation rule, which redirects the user after submitting the login form, Here is an example of this: http://www.mkyong.com/jsf2/jsf-form-action-navigation-rule-example/

您可以使用导航规则,在提交登录表单后重定向用户,这是一个示例:http: //www.mkyong.com/jsf2/jsf-form-action-navigation-rule-example/