#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    4
    Rep Power
    0

    Smile session timeout redirect


    When a session times out, is there a way to redirect the user automatically back to the home page?

    Does anyone have any suggestions?
  2. #2
  3. No Profile Picture
    hmmmm...
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2001
    Location
    UK
    Posts
    37
    Rep Power
    14
    only ever create seesion on the homepage jsp/servlets then on every other jsp/servlet do a getSession without forcing the creation of a new one, then check if it retrieved one :

    if (session != null) { }
    else { redirect to homepage}
    Some things can be more simple than you think....
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2001
    Location
    NE Pa.
    Posts
    96
    Rep Power
    13
    You may also want to look at the SessionBindingListener interface. This is handy for doing all sorts of things when the session object is about to be destroyed, database work, cleanup etc. The interface has two methods that must be overridden by whatever class you use it in, valueBound & valueUnbound. If your sessions are tied to a Listener it will be called right before the session tied to it is destroyed, similar to the finalize() method called prior to garbage collection.

    Its a handy tool for anyone using sessions on a website
    DC Dalton
    DCD Designs
    SCJP
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    4
    Rep Power
    0
    DcDalton, MattWilliams,

    Thank you for your responses. Hopefully, I will figure it out with both of your suggestions. I had been testing for "" or NULL values of Session Variables at the beginning of the jsp page. I guess the main problem is realizing the correct logical placement of this snippet I will be creating. We shall see.....


    Thanks again,
    Angela
  8. #5
  9. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    The correct way to see if someones session has expired is to retrieve a variable that has been set in the session and if it is null, then the session has expired.

    At that point you have a choice. 1) Reinitialize them if you can with the data you have and repopulate the session. 2) redirect them to a login page so that they can be reinitiliazed.
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    4
    Rep Power
    0
    thank you for your suggestions, Nemi. I will try them out and see how it goes.

    Thanks, Angela

IMN logo majestic logo threadwatch logo seochat tools logo