我在 JSF 2.0 中遇到了同样的问题,实现由 IBM Websphere 8.5.5.3 提供。
我尝试使用 ExceptionHandlerWrapper 检查 ViewExpiredException 并重定向到会话过期页面(或登录页面),但我无法消除以下错误,遗憾的是此错误在处理程序之前打印:
StateUtils E View State cannot be reconstructed
但是我设法通过实现一个 servlet 过滤器来解决它,该过滤器将检查任何潜在的 ViewExpiredException,如果有的话,它将重定向到会话过期页面。
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;
HttpSession session = request.getSession(false);
boolean requestContainsViewState = (request.getParameter("javax.faces.ViewState") != null);
boolean potentialViewExpiredException = (session == null && requestContainsViewState);
if (potentialViewExpiredException) {
// No session found and potential ViewExpiredException, redirect to session expired page.
response.sendRedirect(request.getContextPath() + "/pages/error/expired.xhtml");
} else {
chain.doFilter(req, res);
}
编辑:您需要确保这是过滤器链中的第一个过滤器,如果有以前的过滤器并且此过滤器创建了一个会话,则上述解决方案将不适合您。