我正在使用带有Primefaces 3.5的Websphere Portal 8。要求是当会话超时时,用户被重定向到会话超时页面,该页面上有一个按钮,单击该按钮会将用户带回登录页面。 登录页面包含一个portlet,Session Timeout页面也是如此 - 两者都在同一个portlet应用程序中。 我使用ImplicitLogoutFilter成功重定向到会话超时页面:
@Override
public void logout(HttpServletRequest request, HttpServletResponse response, FilterChainContext filterContext, LogoutFilterChain chain) throws LogoutException, LoginException {
chain.logout(request, response, filterContext);
if (filterContext.getRedirectURL() != null) {
if (logger.isLoggable(Level.FINEST)) {
logger.logp(Level.FINEST, CLASS_NAME, MethodName.LOGOUT, "Redirecting to session timeout page: " + SESSION_TIMEOUT_PAGE_URL);
}
filterContext.setRedirectURL(SESSION_TIMEOUT_PAGE_URL);
}
}
会话超时页面上的portlet包含一个按钮,该按钮调用重定向到登录页面的portlet操作:
public void navigateToPortalPage(String pageUniqueName) throws RpmPortalException {
final String methodName = "navigateToPortalPage";
RpmPortalPage portalPage = getNavigationManager().getPortalPage(pageUniqueName, getPortletRequest(), getPortletResponse());
try {
FacesContext context = getFacesContext();
if (context != null) {
context.getExternalContext().redirect(portalPage.getUrl());
context.responseComplete();
}
} catch (IOException e) {
RpmExceptionUtils.logAndThrowException(CLASSNAME, methodName + "(" + pageUniqueName + ")", RpmErrorCode.RPM_CONFIG_00004, getLoggedinUser(), e);
}
}
但是,单击该按钮而不是转到登录页面时,会抛出ViewExpired异常。此异常由异常处理程序处理,该异常处理程序处理异常,重定向到错误页面并向用户显示错误。
我的问题是如何在会话过期后避免ViewExpired Exception,因为我只想在没有发生ViewExpiredException的情况下重定向到登录页面,
提前感谢您的帮助
答案 0 :(得分:2)
我的问题是如何在会话过期后避免ViewExpired Exception,因为我只想在不发生ViewExpiredException的情况下重定向到登录页面
只需将登录页面指定为ViewExpiredException
的错误页面。
<error-page>
<exception-type>javax.faces.application.ViewExpiredException</exception-type>
<location>/login.xhtml</location>
</error-page>
(假设您已在*.xhtml
上映射了面向servlet,否则会相应地更改