Is there a way to detect when the session has expired, so that we can send a redirect to a login page?
Created May 4, 2012
Michael Wax [In our Servlet framework, session timeout happens after 1hr.
Currently if user tires to access the pages after 1hr, he gets
null-pointer exception.
Is there any way we can detect that session has been expired,
so that we can show standard HTML Page to User, indicating that
his session has expired, he has to LOGIN again.]
-----------------
After getting the session, check to see if it is new:
HttpSession session = request.getSession(); if (!session.isNew()) { //do something which requires the session to exist } else { //new session was created - send new login page }[And see http://www.jguru.com/faq/view.jsp?EID=415883 for how to send a redirect to a static login page. -Alex]