Let's see...

(1) You are correct, it's nothing more than an entry in web.xml. Remember, this isn't a Tomcat-specific thing, it's a J2EE thing (servlet spec specifically I think), so it's YOUR APP'S web.xml. The entry is simply:

<listener>
<listener-class>com.company.app.MySessionListener</listener-class>
</listener>

Assuming that class is available to the classloader, your all set.

(2) I'm not too familiar with the Spring framework, but since it's still built on top of the servlet spec, this would apply just the same, it should be independant of app server and framework in use. Spring may have it's own mechanism for doing this, but given the choice I'd chose the standard approach, which is a listener.

(3) I don't have any good references handy, but just Googling SessionListener will turn up plenty of hits. Just to save you some time, here's the basic structure of a SessionListener class:

package com.company.app.MySessionListener

import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;

public class MySessionListener implements HttpSessionListener {

/**
* This method is called by the servlet container just after http session is
* created.
*
* @param <b>event</b> HttpSessionEvent
*/
public void sessionCreated(HttpSessionEvent event) {
}


/**
* This method is called by the servlet container just before http session is
* destroyed.
*
* @param <b>event</b> HttpSessionEvent
*/
public void sessionDestroyed(HttpSessionEvent event) {
}


}

Couldn't be simpler! You can do event.getSession() in both if you need to do anything with the session (like, for the OP, if you have a reference to the user ID who's directory you want to purge of temporary files).

--
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com


Tim Diggins wrote:
that sounds very useful, not something I've done before -- can I ask a few questions -

1) how does one bind that into Tomcat -- declare a session listener in (I presume) web.xml?

2) as I'm using Spring Framework, is this still relevant (or is there a spring-specific way of binding in a session listener --- sorry, ought to ask that on a spring list...)

3) can you recommend the best reference material / sites on managing sessions (standard tomcat docs seem to have nothing on sessions I can find.)

Tim


Frank W. Zammetti wrote:

Write a SessionListener... it has two methods, one that fires when a session is created, one when it is destroyed. That should do the trick for you. That's not a Tomcat-specific solution either, so it should be rather portable should you ever need to move to another app server.



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




.




--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to