Darek,
I've tried your suggestion. As I've said before: I need to access the Session
object. This is what I have:
package abcd;
import java.io.*;
import javax.servlet.http.*;
public class AbcdSessionListener implements HttpSessionBindingListener {
private String userId;
public void valueBound(HttpSessionBindingEvent se) {
HttpSession session = se.getSession();
userId = (String)session.getValue("userId");
}
public void valueUnbound(HttpSessionBindingEvent se) {
AbcdUtil util = new AbcdUtil();
HttpSession session = se.getSession(); // <---This is not possible because
the session is already invalidated at this point.
String userId = (String)session.getValue("userId");
// Clean up the folder of old XML files by the same user from previous
login (uses the AbcdUtil class)
String XML_WORK_PATH = "/WEB-INF/work_xml";
File[] files =
util.fileSearch(session.getServletContext().getRealPath(XML_WORK_PATH), userId +
"_*.*");
for (int i = 0; i < files.length; i++) {
files[i].delete();
}
}
} // End AbcdSessionListener
And I use the following in a JSP:
<jsp:useBean id="listener" class="abcd.AbcdSessionListener" scope="session" />
<%
session.setAttribute("sessionListener", listener);
%>
All this fails with or without a <listener> element in the web.xml entry (and
how should one decide whether or not to put one in web.xml?).
If you read the Servlet API Documentation for the HttpSession Interface
(http://jakarta.apache.org/tomcat/tomcat-5.5-doc/servletapi/index.html), it
says:
"For session that are invalidated or expire, notifications are sent after the
session has been invalidated or expired." Pretty useless, if you ask me.
Any advice?
Franklin
Darek Czarkowski wrote:
You could implement HttpSessionBindingListener and define your own
valueBound and valueUnbound methods.
DarekC
On Fri, 2005-08-26 at 13:08, Franklin Phan wrote:
Is there a way to set Tomcat to call listeners before invalidate() is called on
a session?
I'm trying to code a method to clean up specifically named files inside a working dir (in Windows XP) whenever the session times out. I can't seem to find a way to do it. Apparently,
invalidate() is called prior to calling listeners, and these "specifically named files" that I want to clean up are named after the user ID that is stored in the HttpSession object (meaning
I'd need to access the session object. I understand Resin has a setting called "invalidate-after-listener" and am wondering whether Tomcat has same.
Thanks.
---------------------------------------------------------------------
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]