On Sat, 28 Apr 2001, Sudarson_Pratihar wrote:

> Thanks for the reply. But what you have talked about the Browser
> closing , I'm talking about the stop button(or interrupt) button of
> browser.  Is that applicable for that also?
>
> And if so, how can I destroy the objects that are created within the
> particular servlet.
>
> Pls highlight on the clean up work.

Discussion of this kind of stuff (i.e. basically, how to detect all
scenarios where a user is done with a servlet) has come up on this
list *a lot*.  The best/strongest consensus is that, while you can do
some tricks (typically using JavaScript or an applet) that will detect
a greater number/variety of these scenarios, there is no way to do it
100% reliably.  This means that ultimately you will have to rely on
some timeout mechanism.  That is, you set a idle timeout --
programmatically if you desire, it's in the API in the most recent
versions -- for your sessions.  Sessions will become invalidated upon
the timeout.  And then you can use HttpSessionBindingListener to catch
those invalidations, and do whatever cleanup you need to do.  Check
the spec and the API for more info.  This kind of cleanup is tied to
things that are placed in sessions.

For cleanup of things that are only in the servlets, you use the
servlet's destroy() method.  However, you never worry about calling
destroy yourself, that is part of the servlet lifecycle and is
controlled by the servlet container.


> > ----------
> > From:         Tarun Ramakrishna Elankath[SMTP:[EMAIL PROTECTED]]
> > Reply To:     A mailing list for discussion about Sun Microsystem's Java
> > Servlet API Technology.
> > Sent:         Friday, April 27, 2001 8:36 PM
> > To:   [EMAIL PROTECTED]
> > Subject:      Re: How to detect browser stop -- it is possible!
> >
> > Well IT IS actually possible for the browser to inform the server that it
> > has been closed.! You would have to do the scripting via JavaScript
> > though.
> > You could set a onunload() event handler for the window. This onunload
> > event
> > handler could then call a server-side script with the parameter
> > close=true.
> > The server-side script could then use this information to perform
> > some-clean
> > up operations. However the sever-side script SHOULD NOT write to the
> > client,
> > because by that time IE/NS would have closed the window down.
> >
> > A rough outline of how this works is like follows :
> >
> >   <script language="javascript">
> >    window.onunload = function() {
> >         location.href="detect_close.jsp?close=true";
> >    }
> >   </script>
> >
> > You could do whatever you want in the JSP. Note that the JSP WILL KNOW
> > which
> > client has shut the window, because the browser would send the
> > session/cookie data in the request just before the window shuts down.
> >
> > ----- Original Message -----
> > From: "Kevin Mukhar" <[EMAIL PROTECTED]>
> > To: <[EMAIL PROTECTED]>
> > Sent: Friday, April 27, 2001 7:56 PM
> > Subject: Re: How to detect browser stop
> >
> >
> > > Sudarson_Pratihar wrote:
> > > >
> > > > Is there any way to detect browser stop?
> > >
> > > No. It's been a while since we had this discussion here, but the answer
> > > is still the same: the browser does not notify any server when the
> > > browser is stopped or exited. You might want to check the archives to
> > > review past discussions on this topic.
> > >
> > > > So that if a user clicks the
> > > > browser stop, the servlet at the server side can be destroyed.
> > >
> > > You don't want to do this anyway. The servlet is a server resource and
> > > should generally be available as long as the server is running. The best
> > > way to deal with this situation is just to catch the IOException that is
> > > thrown when the servlet tries to send the response to the client; since
> > > the client no longer wants the response, there's really nothing else to
> > > be done.
[ ... ]

Milt Epstein
Research Programmer
Software/Systems Development Group
Computing and Communications Services Office (CCSO)
University of Illinois at Urbana-Champaign (UIUC)
[EMAIL PROTECTED]

___________________________________________________________________________
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