2 Replies Latest reply on Feb 14, 2013 9:58 AM by Philip H

    do something on session timeout

    Philip H Newbie

      hi there.

      ive been looking up ideas on how to do something on a session timeout and came up with adding this to my web.xml:







      and implementing a js on my testpage which looks like that:


      <?xml version='1.0' encoding='UTF-8' ?>

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

      <html xmlns="http://www.w3.org/1999/xhtml"











              <a4j:outputPanel ajaxRendered="true">

                  <script type="text/javascript">


      A4J.AJAX.onExpired = function(loc, expiredMsg){


          if(window.confirm("Custom onExpired handler "+expiredMsg+" for a location: "+loc)){


            return loc;


          } else {


           return false;













      But the frustating issue here is that just nothing happens.

      To be clear what i want is that if the session times out, i want a method called in my backing bean to do smth on the database.
      Is this the right way to do this and i just missed out some tiny detail or totally the wrong approach ?
      Thank you in advance

        • 1. Re: do something on session timeout
          Erdem YILMAZ Newbie


          why do not prefer HttpSessionListener?

          here an example:


          import javax.servlet.http.HttpSessionEvent;

          import javax.servlet.http.HttpSessionListener;


          public class SessionListener implements HttpSessionListener {

              public void sessionCreated(HttpSessionEvent event) {


                  System.out.println("Session Created: " + event.getSession().getId());

                  System.out.println("Total Sessions: " + sessionCount);



              public void sessionDestroyed(HttpSessionEvent event) {

                  System.out.println("Session Destroyed: " + event.getSession().getId());

                  System.out.println("Total Sessions: " + sessionCount);






          • 2. Re: do something on session timeout
            Philip H Newbie

            thx a lot for your answer, its perfectly doing what i want. the funny thing is that i just looked it up 5 minutes before i read your answer. but thx a lot anyway.


            ONLY one thing might be important for anyone who has the same issue- you need to register that listener in the web.xml like this:





            best wishes