tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marco Schmalz <ma...@schess.ch>
Subject Re: Replacement for HTTPSessionContext!?
Date Fri, 28 Sep 2001 10:19:46 GMT
 > I am looking for a way to get a list of sessions and then invalidate 
them.

use a Set with all sessions in it and store it in the ServletContext.

btw, im more likely to write code than to explain it with words. voilĂ :


//create a set to store the sessions and put it into the ServletContext
Set sessions = Collections.synchronizedSet(new HashSet());
getServletContext().setAttribute("myproj.sessions", sessions);

//when a user logs in:
Set sessions = (Set)getServletContext().getAttribute("myproj.sessions");
sessions.add(request.getSession());

//when you want to invalidate all sessions:
Iterator sessionIt = 
((Set)getServletContext().getAttribute("myproj.sessions")).iterator();
while(sessionIt.hasNext()) {
	HttpSession session = (HttpSession)sessionIt.next();
	session.invalidate();
}



i hope this helps
marco








Mime
View raw message