Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Invalidate Question

 
Gus Mus
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any way to know if the session is invalidated or not ?
 
Arron Zhang
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
package arron;
import javax.servlet.http.HttpSessionListener;
import javax.servlet.http.HttpSessionEvent;
public class SessionCount implements HttpSessionListener {

private static int activeSessions = 0;
public static int getActiveSessions() {
return activeSessions;
}
public void sessionCreated(HttpSessionEvent e) {
activeSessions++;
}

public void sessionDestroyed(HttpSessionEvent e) {
if(activeSessions > 0) activeSessions--;
}
}
 
Geeta Ramasami
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
For this u can implement the HttpSessionBindingListener Interface.There u have 2 methods valueBound and valueUnBound.
When a session is invalidated the valueUnBound is called inside which u can write some logic to hold the identification of the session invalidation.
Geeta
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic