Results 1 to 3 of 3

Thread: trap and handle session timeout

  1. #1
    Join Date
    Sep 2008
    Posts
    12

    Default trap session timeout and display message to user

    I have written an interceptor according to what I found in another thread opn this forum to catch session timeouts.
    Code:
        public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
            HttpSession session = request.getSession();
            session.
            if (session == null) {
                request.setAttribute("timeout", "Your session has timed out. "
                        + "Please log in again if you want to continue to use FI-RACE.");
                response.sendRedirect("/login.jsp");
                return false;
            }
            return super.preHandle(request, response, handler);
        }
    this interceptor gets called, but the session is never null.

    Does anyone have any suggestions as to what I need to check to know that the session has timed put?
    Last edited by drellim; Sep 26th, 2008 at 08:43 AM. Reason: better subject

  2. #2
    Join Date
    Oct 2006
    Posts
    228

    Default

    Quote Originally Posted by drellim View Post
    HttpSession session = request.getSession();
    This creates a session if it doesn't already exist, hence why session is never null.

    request.getSession(false) will only return a session if it already exists.

  3. #3
    Join Date
    Sep 2008
    Posts
    12

    Default

    I think I've tried getSession(false) without success. I will have another go when I get a chance

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •