gpt4 book ai didi

jsf - 重定向到 JSF 中的外部 URL

转载 作者:行者123 更新时间:2023-12-03 08:13:22 25 4
gpt4 key购买 nike

我一直在处理 JSF 的一个问题,当涉及到重定向到我的应用程序内的页面时,它工作得很好,但我一直无法重定向到外部 URL,有人可以指导我吗?

最佳答案

要么直接在<a>中提及URL或 <h:outputLink> .

<a href="https://stackoverflow.com">Go to this site!</a>
<!-- or -->
<h:outputLink value="https://stackoverflow.com">Go to this site!</h:outputLink>
或者,如果您需要使用 <h:commandLink> 调用 bean 操作像下面,
<h:form>
<h:commandLink value="Go to this site!" action="#{bean.redirect}" />
</h:form>
然后使用 ExternalContext#redirect() 在行动方法。
public void redirect() throws IOException {
// ...

ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
externalContext.redirect("https://stackoverflow.com");
}
请注意,您不需要捕获该 IOException ,服务器会处理。还要注意在 URL 中包含方案( https://http://// )的重要性,否则它将相对于当前域进行解释。

关于jsf - 重定向到 JSF 中的外部 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5092439/

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