tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alex Colic" <alex.co...@pop-ware.com>
Subject Re: Replacement for HTTPSessionContext!?
Date Fri, 28 Sep 2001 11:55:49 GMT

Thanks alot all.

Marco the below code was great. It was just what I needed. I have a web
application that talks to a VB backend. When the VB backend is shut down I
need all sessions invalidated. I tried implementing a session listener but
just because the VB back end goes down doesn't mean the session is
invalidated. I needed a way to iterate through the session and kill the
objects. The below code should work really well.

Thanks


Alex
**********************
To: tomcat-user@jakarta.apache.org
From: Marco Schmalz <marco@schess.ch>
Subject: Re: Replacement for HTTPSessionContext!?
Message-ID: <3BB44EC2.80801@schess.ch>

 > 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