我有一个检查会话的过滤器。我的过滤器:
public class FilterLogin implements Filter{
FilterConfig fc;
@Override
public void init(FilterConfig filterConfig) throws ServletException {
//throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
fc = filterConfig;
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
//throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse resp = (HttpServletResponse) response;
HttpSession session = req.getSession(true);
if (session.getAttribute("loginMB") == null) {
resp.sendRedirect("/home.xhtml");
} else {
chain.doFilter(request, response);
}
}
@Override
public void destroy() {
//throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
网页.xml:
<filter>
<filter-name>filter</filter-name>
<filter-class>pl.ePrzychodnia.filter.LoginFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>filter</filter-name>
<url-pattern>/protected/*</url-pattern>
</filter-mapping>
<error-page>
<exception-type>javax.faces.application.ViewExpiredException</exception-type>
<location>/home.xhtml</location>
</error-page>
会话到期后,我应该访问站点 home.xhtml。但是当会话过期并且我想单击页面中的导航菜单时,组件对单击没有反应......当我不使用 Primefaces 时,一切正常。当我在我的项目中使用 primefaces 时,我遇到了这个错误。可能是什么原因?
我尝试使用全局异常处理程序,但我有一个小问题。我从这个网站复制课程 http://wmarkito.wordpress.com/2012/04/05/adding-global-exception-handling-using-jsf-2-x-exceptionhandler/
并在 CustomExceptionHandler 类中编辑:
try {
//log error ?
log.log(Level.SEVERE, "Critical Exception!", t);
//redirect error page
requestMap.put("exceptionMessage", t.getMessage());
nav.handleNavigation(fc, null, "/home");
fc.renderResponse();
// remove the comment below if you want to report the error in a jsf error message
//JsfUtil.addErrorMessage(t.getMessage());
}
我改变:nav.handleNavigation(fc, null, "/error");
到nav.handleNavigation(fc, null, "/home");
但是,当会话超时时,我不会重新编辑到 home.xhtml 页面,只有在我单击时才会转到该页面,并且我有一个示例错误:
SEVERE: Critical Exception!
javax.faces.application.ViewExpiredException: viewId:/protected/admin/about.xhtml - View /protected/admin/about.xhtml could not be restored.
当我的会话到期时单击“关于”页面的引用时。我看到一个不完整的 about.xhtml 页面而不是 home.xhtml