java从支持bean导航到外部URL?
我正在尝试为我的JavaEE/JSF2应用程序实现正确的注销
它需要两件事:
- 我需要从JAAS注销并使会话无效
- 然后,我必须导航到一个外部URL以启动Siteminder注销
Siteminder注销URL(在策略服务器上配置->;我无法更改)不在我的应用程序上下文中。如果我的webapp URL是https://localhost:8080/sm/MyWebApp,那么注销URL是https://localhost:8080/anotherwebapp/logout.html
这是当前本地注销代码:
public void logout() {
System.out.println("Logging out...");
HttpServletRequest request = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
try {
request.logout();
} catch (ServletException e) {
e.printStackTrace();
}
HttpSession session = (HttpSession)FacesContext.getCurrentInstance().getExternalContext().getSession(false);
if (session != null) {
session.invalidate();
}
}
以下是生成注销URL的属性:
public String getLogoutUrl() {
HttpServletRequest request = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
String requestServer = request.getServerName();
String requestScheme = request.getScheme();
int serverPort = request.getServerPort();
String logoutUrl = requestScheme + "://" + requestServer + ":" + Integer.toString(serverPort) + "/anotherwebapp/logout.html";
return logoutUrl;
}
但是,我找不到可以调用logout()然后打开外部URL的JSF2/Primefaces组件。例如,如果我有:
<h:outputLink value="#{authBean.logoutUrl}" onclick="#{authBean.logout()}">[Logout]</h:outputLink>
那么onclick似乎没有被调用
我尝试的另一种方法是将外部URL放在注销函数的末尾,使其作为导航字符串返回,但无法识别(也尝试了使用“?faces redirect=true”…)
任何帮助都将不胜感激
# 1 楼答案
您也可以只使用^{}
不需要中间页面和元刷新
# 2 楼答案
您可以创建一个页面注销。xhtml,因此代码如下所示:
并在页面中添加: