0 Replies Latest reply on Aug 12, 2004 4:38 AM by ashishabrol

    session expire handling

    ashishabrol

      Hi guys .

      Can anyone tell me a way of redirecting a user to the home page from another page after the session has expired and also put an object in the sesssion variable after the session has expired .Because when I try to redirect a user to the Home page after the session expires using "response.sendRedirect" I get the NullPointerException

      This is my class that implements the HttpSessionListener listener and tries to redirect to the home page on the expiry of a session.

      ///////////////////////////////////////////////////////////////////////////////
      public class SessionMaintainence implements HttpSessionListener //, HttpSessionListener
      {

      private String strUsername;
      private HttpServletRequest request;
      private ServletContext application;
      private long createTime;
      private String sIPAddrress;
      private Vector sessionNames;
      private HttpSession session;
      private HttpServletResponse response;
      private static int activeSessions = 0;

      public SessionMaintainence()
      {
      }

      public SessionMaintainence(HttpServletRequest req, String userID , ServletContext sc, long ctime, String sIP)
      {
      strUsername = userID;
      request = req;
      application = sc;
      createTime = ctime;
      sIPAddrress = sIP;
      session = request.getSession();
      }
      public SessionMaintainence(String userID, Vector sessionNames, ServletContext sc)
      {
      strUsername = userID;
      application = sc;
      this.sessionNames = sessionNames;
      }

      public void sessionCreated(HttpSessionEvent se) {
      activeSessions++;
      }

      public void sessionDestroyed(HttpSessionEvent se) {
      if(activeSessions > 0)
      activeSessions--;
      try{
      response.sendRedirect(Global.BASE_URL + Global.WELCOME_URL);
      session.setAttribute("errorMessage","Please login again.");
      }catch(Throwable e){
      e.printStackTrace();
      }
      }

      public static int getActiveSessions() {
      return activeSessions;
      }
      }
      ///////////////////////////////////////////////////////////////////////////////


      Thanks.