Search code examples
jsfprimefacesglassfishhttpsession

Why is my httpsession expiring?


I'm pretty new to JSF and I ran into an interesting problem. I have a web application, with a session timeout specified and even if I make actions, the session expires. As far as I know, every new request restarts the timeout counter, well it is not happening. Also, during development I noticed, that after timeout (redirected to the login page), if I reload the page, the session is still valid. Same session Id, counter still going... I have no idea what is wrong, I am using Glassfish and PrimeFaces.

I googled a lot, even tried to catch the ViewExpiredException, but with no luck. The redirection is done using the

<meta http-equiv="refresh" content="#{session.maxInactiveInterval};url=login.jsf?reason=expired>

method. Maybe I am missing something obvious in the web.xml, I am out of ideas.

Please give me some advice on this, thank you very much!


Solution

  • The approach you are using is not the best fit for implementing session timeout, The reason is meta tag will refresh the page on a specific interval, and in your case it redirects to another url on refresh,

    i.e., if value of session.maxInactiveInterval is 5, the page will be refreshed in 5 seconds and redirects to login.jsf?reason=expired, regardless of the actions you make. only page refresh will reset the counter.

    Learn more about meta tags here

    If you want to implement idle monitor, i suggest you to have a look at <p:idleMonitor> at Primefaces showcase - IdleMonitor