I'm noticing some strange behaviour with a class that implements 
HttpSessionListener and is registered in my apps webapp.xml file as a 
listener.

When I call session.getAttribute("xxx") on a session passed into 
sessionDestroyed() the thread seems to lock.

I've simplified my class as a test case and it never makes it to the 
System.out.println("attribute shown") statement.

I'm running tomcat 4.0 final on windows 2k. I've received the same 
results on both jdk 1.3.1 and 1.4 beta.

My test includes two JSP pages: one sets a value in the session, another 
calls session.invalidate().

output from stdout.log and class definition are included bellow.

Thanks in advance....

~Scott

output from stdout.log
----
Create Catalina server
Starting service Tomcat-Standalone
Apache Tomcat/4.0
ServletContext Initialized
Starting service Tomcat-Apache
Apache Tomcat/4.0
Session Created <-- click on populateSession.jsp
attribute added
Session Destroyed <- click on invalidateSession.jsp
                             <- execution stops before showing attribute 
value
----



import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class LoggingController implements ServletContextListener, 
HttpSessionListener
{
     
    public LoggingController()
    {
        // System.out.println("LoggingController constructed");
    }

    public void contextInitialized(ServletContextEvent sce)
    {
        System.out.println("ServletContext Initialized");
    }

    public void contextDestroyed(ServletContextEvent sce)
    {
            System.out.println("ServletContext Destroyed");
    }    

    public void sessionCreated(HttpSessionEvent hse)
    {
        System.out.println("Session Created");
                
                HttpSession session = hse.getSession();
                session.setAttribute("name", "scott");
                
                // execution makes it here ok
                System.out.println("attribute added");
    }
        

    public void sessionDestroyed(HttpSessionEvent hse)
    {
        System.out.println("Session Destroyed");
        
        HttpSession session = hse.getSession();
            
        // seems to hang up on the following line
        System.out.println(session.getAttribute("name"));
            
       System.out.println("attribute shown");
    }
}



Reply via email to