Shapira, Yoav schrieb:

> It depends on how much work you want to do.  It's not a good idea for
> your to depend on implementation details of the Catalina session fa�ade.
> However, the session ID is a primitive (String) which is serializable.
> So instead of storing a reference to the session, store a reference to
> the session ID.  Have an HttpSessionListener which keeps a Map of
> session IDs to sessions.  You can get the session for a given session ID
> from your listener as needed.
> 
> This solution is container-independent and portable.

I tried it this way. But the problem is, that since the listener itself is
not in a session context, the Map is empty when the application is reloaded.

That's how I tried it:

public class SessionListener implements HttpSessionListener,
java.io.Serializable
{
    private HashMap sessions = new HashMap();
    static private SessionListener instance;

    /** Creates a new instance of SessionListener */
    public SessionListener()
    {
        instance = this;
    }

    static public SessionListener getInstance()
    {
        assert (instance != null);
        return instance;
    }

    public void sessionCreated(HttpSessionEvent httpSessionEvent)
    {
        HttpSession session = httpSessionEvent.getSession();
        synchronized (sessions)
        {
            sessions.put(session.getId(), session);
        }
    }

    public void sessionDestroyed(HttpSessionEvent httpSessionEvent)
    {
        HttpSession session = httpSessionEvent.getSession();
        synchronized (sessions)
        {
            sessions.remove(session.getId());
        }
    }

    public HttpSession getSession(String id)
    {
        synchronized (sessions)
        {
            return (HttpSession)sessions.get(id);
        }
    }
}


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

Reply via email to