Here is a small but working example.

        In the servlet, I put something like:
                CMFSSession medianSession=null;
                medianSession = (CMFSSession)
session.getValue("cmfssession");

                if (medianSession == null) {
                        medianSession = new CMFSSession();
                        session.putValue("cmfssession", medianSession);
                }


medianSession.setMSession(data1.getMSession(session.getId()));

                With the following CMFSSession implementation:

import javax.servlet.*;
import javax.servlet.http.*;

/**
*
* @author                               Jean-Michel Augusto
*/

public class CMFSSession implements HttpSessionBindingListener {

        int medianSession = -1;

        public CMFSSession() {
        }


        protected void finalize() {
                medianSession = -1;
        }

        public synchronized void setMSession(int msession) {
                medianSession = msession;
                System.err.println("CMFSSession setmession with
id="+medianSession);
        }

        public int getMSession() {
                return medianSession;
        }

        /**
        */
        public void valueBound(HttpSessionBindingEvent event) {
                String objName = event.getName();
                HttpSession session = event.getSession();

                System.err.println("CMFSSession bound with name =
"+objName+
                        " and session="+session.getId()+ " and
id="+medianSession);
        }

        /**
        * function called when the object is unbound from the session
        */
        public void valueUnbound(HttpSessionBindingEvent event) {
                String objName = event.getName();
                HttpSession session = event.getSession();

                System.err.println("CMFSSession unbound with name =
"+objName+
                        " and session="+session.getId()+ " and
id="+medianSession);

                CMFSdataAcq tempo = new CMFSdataAcq();
                if (medianSession>=0) {
                        tempo.deleteMSession(medianSession);
                }

        }
}

        Please note that all during the valueBound, the code does
nothing excepting logging in err (I am currently debugging my
application:-))) ) but during the unbound event, I remove the session
data (represented here by the CMFSdataAcq).

        Hope this help

Friendly,
Jean Michel
[EMAIL PROTECTED]

> -----Original Message-----
> From: Sue Ho [mailto:[EMAIL PROTECTED]]
> Sent: Monday, May 10, 1999 17:09
> To: [EMAIL PROTECTED]
> Subject: Re: How to know when an user logout??
>
>
> do you have some examples to share? thanks
>
> -----Original Message-----
> From:   Michael Caines [SMTP:[EMAIL PROTECTED]]
> Sent:   Saturday, May 08, 1999 12:07 PM
> To:     [EMAIL PROTECTED]
> Subject:        Re: How to know when an user logout??
>
> You can also use the HttpSessionBindingListener interface if
> you want a class
> to be notified when objects are added to and/or removed from
> an HttpSession.
> You could use this to gracefully close DB connections, etc.
> when objects are
> removed from the session.  Objects can be removed from the
> session either
> explicitly by the programmer, or by the servlet engine after
> the time-out
> period has elapsed.
>
> Michael
>
>
> Gilad Tiram wrote:
>
> > Hello Andreas,
> >
> > You can save the user resources in Session which is
> actually will take
> > resources on the client side.
> > I think that this session is killed automatically  after
> some time out.
> >
> > Gilad.
> >
> >         -----Original Message-----
> >         From:   Andres Portillo [SMTP:[EMAIL PROTECTED]]
> >         Sent:   Monday, May 03, 1999 7:14 PM
> >         To:     [EMAIL PROTECTED]
> >         Subject:        How to know when an user logout??
> >
> >         Hi everybody:
> >
> >             Do you know if there is way to know when a user
> is not longer
> > using
> >         a servlet (like a logout). By example an user
> >         login in my servlet, when this happen the servlet
> creates some
> > resources
> >         and save handles to that resources in the session
> >         associated with that user. I'd would like to know
> when the user
> > logout
> >         (shutdown the browser, or go to another web page)
> >         so the servlet can release those resources...
> >
> >             I would appreciate any help.. Thanx
> >
> >         Andres Portillo
> >
> >

___________________________________________________________________________
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