Hi,

I'm using JavaWebServer 2.0 and i want to do this:

Each client joins a new session in which some sessionbeans are
shared between some servlets, but when the session ends i want to
check the database (for some reason which is not relevant to my prob)

I used a httpsessionbindinglistener for this..., and in the method, valueUnbound, i 
check my database.

But what happens is that as soon as a second servlet joins the session
it checks my database...

It only may do this when the session ends, after about 30 minutes i think.
So, after LookupCompactDisc, if AddToBasket is started, it checks immediate
the database

Can you tell me what i did wrong, or give me another sollution to
accomplish my goal?

Thnx!

Best Regards,

Jochen Vastmans
[EMAIL PROTECTED]


// here is a piece of my code
// LookupCompactDisc will start a new session and AddToBasket will join
// that session.
// CustomerBindingListener implements the HttpSessionBindingListener.

public class LookupCompactDisc extends HttpServlet implements    SingleThreadModel{

   ...

   public void doPost(HttpServletRequest req, HttpServletResponse res){

      try {
 Vector compactdiscs = new Vector();

 // new servletsession is created
 HttpSession session = req.getSession(true);

 String artist=req.getParameter("artist").toLowerCase();
 String title=req.getParameter("title").toLowerCase();

 cs = (CustSession)session.getValue("CustomerSession");

 // a new listener is created and added to the session as new
        // argument
 if(cs == null){
     createSessionBean();
     compactdiscs=cs.lookupCompactDisc(artist,title);
     session.putValue("CustomerSession",cs);
     listener =  new CustomerBindingListener((CustSession)cs);
session.putValue("bindings.listener",(CustomerBindingListener)listener);
 }
 else{
     compactdiscs=cs.lookupCompactDisc(artist,title);
     session.putValue("CustomerSession",cs);
listener = (CustomerBindingListener)session.getValue("bindings.listener");
     listener.setCustSession((CustSession)cs);
session.putValue("bindings.listener",(CustomerBindingListener)listener);      }
 ...
 }
 catch (Exception e) {
     e.printStackTrace();
 }
     }
     ...
}

public class AddToBasket extends HttpServlet implements SingleThreadModel{
 ...

   public void doPost(HttpServletRequest req, HttpServletResponse res){

 try {

      //Join a servletsession
      HttpSession session = req.getSession(true);

      cs = (CustSession)session.getValue("CustomerSession");
listener = (CustomerBindingListener)session.getValue("bindings.listener");


      String pid=req.getParameter("id");
      long id = (long) Integer.valueOf(pid).intValue();

             cs.addItemToBasket(id,1);

      // session arguments are updated with changed listener and cs
      session.putValue("CustomerSession",(CustSession)cs);
      listener.setCustSession((CustSession)cs);
session.putValue("bindings.listener",(CustomerBindingListener)listener);

 ...
 }
 catch (Exception e) {
  e.printStackTrace();
 }
 }
 ...
}

public class CustomerBindingListener implements HttpSessionBindingListener {

   ...

   public void valueBound(HttpSessionBindingEvent event){}

   public void valueUnbound(HttpSessionBindingEvent event) {
      try{
  custsession.checkOrder();
      }
      catch(RemoteException e){
    System.err.println("Cannot check order + : "+e);
      }
   }

   ...
}

___________________________________________________________________________
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

Reply via email to