Any way to anticipate session timeout?

佐手、 提交于 2019-12-04 16:56:59

You should be able to register an HttpSessionListener for your webapp that will allow you to get notified when a Session is destroyed.

It has two callback methods:

  • public void sessionCreated(HttpSessionEvent se)
  • public void sessionDestroyed(HttpSessionEvent se)

The HttpSessionEvent class has a getSession method that should let you get the affected session.

The listener class is registered in the web.xml

<listener>
  <description>My Session Listener</description>
  <listener-class>
    my.package.MySessionListener
  </listener-class>
</listener>

Have the user object implement HttpSessionBindingListener, then it can see for itself when it is added to or removed from the session.

You can always ad a piece of JSP that will check to see if your session is still active or valid - basically check to see if a session var exists (!=null) and if it doesn't - redirect the user to another page -

<% 
// check for session object
HttpSession validuser = request.getSession(); 
// check to see if session var exists
if (validuser.getValue("auth_user") == null) { 
response.sendRedirect("admin3.jsp?access+denied");
}
// if the session var is null then redirect the user

Hope this helps Mark

Source : http://www.coderanch.com/t/279538/JSP/java/jsp-session-timeout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!