Hello Gerald,

You can create an object that implements HttpSessionListener
interface and override the valueUnbound method to call the
remove method or whatever you need to to with the SB.

Put it in the session, and when the session expires the
valueUnbound method is invoked. Be sure to implement the
java.io.Serializable interfaz to allow session persistence across
server restarts.

We use this technique for our Shopping Cart, and it has worked
pretty well so far.

Here is the class we use:

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import com.enkamino.cart.*;

/**
 *
 * @author  Rafael Alvarez
 * @version 1.1
 */

public class ControlSesion implements HttpSessionBindingListener,java.io.Serializable{
    ShoppingCart cart; // This hold the reference to the SB, becuse
                       // you can't access to the session to retrieve
                       //it.
    /** Creates new ControlSesion */
    public ControlSesion(ShoppingCart cart) throws java.rmi.RemoteException{
        this.cart = cart;
    }

    public void valueUnbound(final javax.servlet.http.HttpSessionBindingEvent be) {
        try {
            this.cart.clear();
        } catch (Exception e) {
            java.rmi.RemoteException re = new
            java.rmi.RemoteException("Error clearing the Cart ",e);
            re.printStackTrace();
        }
       
    }
    public void valueBound(final javax.servlet.http.HttpSessionBindingEvent be) {
    }
}


GG> I posted this msg this morning, but I haven't seen it appear on the list 
GG> yet. I'm reposting in case it was lost ...

-- 
Best regards,
 Rafael                            mailto:[EMAIL PROTECTED]



Reply via email to