Search code examples
jakarta-eeservletshttpsession

Servlet automatic navigation after session expire


Hi folks when I searched that How can I capture event on session expire then I found that HTTPSessionListener is available for this purpose.But while using that class I collided with another problem.Actually I want that when someone's session expire(as I have fixed that every user session should expire after 10 min) then it automatically navigate to my home page.Even without click on client side(browser) because I haven't found request and response objects in HTTPSession class so i am unable to redirect.
Thanks


Solution

  • It is correct that you can capture session creation/termination in an HTTPSessionListener implementation but this has nothing to do with how to redirect a user after session termination.

    If i got that right, you want to redirect a user after 10 minutes of inactivity to the home page. Well that could be done through javascript and not by your application/web server. This is because a request is done using the stateless http protocol (http://stackoverflow.com/questions/4913763/what-does-it-mean-when-they-say-http-is-stateless)

    To do this using javascript:

    var delay = xxxxx; //The delay is in milliseconds
    setTimeout(function(){ window.location = URL; }, delay);