在JSF Web应用程序中处理'session expired',在JBoss AS 5中运行 [英] Handling 'session expired' in JSF web application, running in JBoss AS 5

查看:118
本文介绍了在JSF Web应用程序中处理'session expired',在JBoss AS 5中运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题与我的另一个问题有关如何在Java Web应用程序中的Session过期时重定向到Login页面?。以下是我正在尝试做的事情:

This question is related to my other question "How to redirect to Login page when Session is expired in Java web application?". Below is what I'm trying to do:


  1. 我在JBoss AS 5上运行的JSF Web应用程序

  2. 如果用户处于非活动状态,例如15分钟,我需要注销用户并将其重定向到登录页面,如果他在会话过期后尝试使用该应用程序。

  3. 因此,正如' JSF Logout and Redirect '中所述,我已经实现了一个过滤器,用于检查会话过期情况,并在会话过期时将用户重定向到session-timed-out.jsp页面。

  4. 我添加了SessionExpiryCheckFilter在web.xml中的所有其他过滤器定义之上,以便我的会话到期检查将始终获得第一次。

  1. I've a JSF web application running on JBoss AS 5
  2. When the user is inactive for, say 15 minutes, I need to log out the user and redirect him to the login page, if he is trying to use the application after the session has expired.
  3. So, as suggested in 'JSF Logout and Redirect', I've implemented a filter which checks for the session expired condition and redirects the user to a session-timed-out.jsp page, if the session has expired.
  4. I've added SessionExpiryCheckFilter on top of all other filter definitions in web.xml, so that my session expiry check will get the first hit always.

现在来我面临的挑战。由于我使用的是JBoss AS,当会话过期时,JBoss会自动将我重定向到登录页面(请注意,不会调用会话到期检查过滤器)。因此,在我登录后,我的SessionExpiryCheckFilter拦截了请求,并且它看到会话可用。但是,它抛出异常 javax.faces.application.ViewExpiredException:viewId:/mypage.faces - 无法恢复视图/mypage.faces。

Now comes the challenge I'm facing. Since I'm using JBoss AS, when the session expired, JBoss automatically redirects me to the login page (note that the session expiry check filter is not invoked). So, after I log-in, my SessionExpiryCheckFilter intercepts the request, and it sees a session is available. But, it throws the exception javax.faces.application.ViewExpiredException: viewId:/mypage.faces - View /mypage.faces could not be restored.

以前有人遇到过这个问题吗?有什么想法可以解决这个问题吗?

Have anyone faced this issue before? Any ideas to solve this issue?

推荐答案

以下方法对我有用。请注意,您必须使用JSTL核心taglib重定向而不是jsp重定向才能使其正常工作(因为jsp也会过期)。

The following approach works for me. Note that you have to use the JSTL core taglib redirect and not the jsp redirect in order for this to work (as the jsp also expires).

FacesConfig.xml 您放置以下内容:

In your FacesConfig.xml you put the following:

<error-page>
    <exception-type>javax.faces.application.ViewExpiredException</exception-type>
    <location>/sessionExpired.jsf</location>
</error-page>

sessionExpired.jsp

sessionExpired.jsp:

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<c:redirect url="/login.jsf" />

您还可以将此方法用于其他错误类型或例外。例如,元素包含错误代码或异常类型与Web应用程序中资源路径之间的映射。:

You can also use this approach for other error types or exceptions. For example the element contains a mapping between an error code or exception type and the path of a resource in the web application.:

<error-page>
    <error-code>400</error-code>
    <location>/400.html</location>
</error-page>

或元素包含Java异常类型的完全限定类名。

or element contains a fully qualified class name of a Java exception type.

<error-page>
    <exception-type>javax.servlet.ServletException</exception-type>
    <location>/servlet/ErrorDisplay</location>
</error-page>

这篇关于在JSF Web应用程序中处理'session expired',在JBoss AS 5中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆