gpt4 book ai didi

从 Java bean 重定向 JSF 页面

转载 作者:行者123 更新时间:2023-12-03 07:49:06 26 4
gpt4 key购买 nike

有什么方法可以从Java方法重定向页面到其他页面吗?

我只能使用以下方式转发它:

FacesContext.getCurrentInstance().getExternalContext().dispatch("/foo.xhtml");

或使用faces-config.xml的导航规则。

你有什么想法吗?

最佳答案

不确定您想要什么,但 ExternalContext#dispatch() 只执行转发,而不执行重定向。您想使用ExternalContext#redirect()相反。

externalContext.redirect("foo.xhtml");

甚至外部(这是不可能通过调度实现的)

externalContext.redirect("http://stackoverflow.com");

您通常希望在 bean 的操作方法中执行此操作。

<小时/>

由于您在评论中提到了 JavaScript,因此以下是使用 JS 进行重定向的方法:

window.location = "foo.xhtml";
// Or
window.location = "http://stackoverflow.com";

关于从 Java bean 重定向 JSF 页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5955130/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com