Here is an example 2 files .

-----Original Message-----
From: A mailing list for discussion about Sun Microsystem's Java Servlet
API Technology. [mailto:[EMAIL PROTECTED]]On Behalf Of
Andrew Beacock
Sent: Thursday, March 09, 2000 7:59 AM
To: [EMAIL PROTECTED]
Subject: Re: How to use HttpSessionBindingEvent?


Phil,

> Could anybody give me a simple code example to show me how to use
> HttpSessionBindingEvent,HttpSessionBindingListener?
> I couldn't find a tutorial on that topic, thanks

It very simple, just implement the HttpSessionBindingListener and
Serializable (required for session binding), then code as follows in you
object;

<code>

import javax.servlet.http.*;

public class BoundObject implements Serializable,
HttpSessionBindingListener {
    private String something = null;

    public BoundObject (String something) {
        this.something = something;
    }

    public otherMethod () {
        ...
    }

    ...

    /**
     * this is the bound method that you have to implement defined in
the interface
     */
    public void valueBound (HttpSessionBindingEvent event) {
        System.out.println (toString () + ".valueBound: I've been bound
to \"" + event.getName () + "\" for session id: " + (event.getSession
()).getId ());
    }

    /**
     * this is the unbound method that you have to implement defined in
the interface
     */
    public void valueUnbound (HttpSessionBindingEvent event) {
        System.out.println (toString () + ".valueUnbound: I've been
unbound from \"" + event.getName () + "\" for session id: " +
(event.getSession ()).getId ());
    }
}

</code>

The session.putValue () ends up calling the valueBound () method, and
the session.invalidate () calls the other one.
The servlet container should always send the unbound event when it times
out the session.

Hope this helps,

Andrew Beacock
Software Team Leader
InterVoice-Brite Ltd.

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Binder.java

SessionObject.java

Reply via email to