FAQ
Hi everybody,

I have big problems when the users of my web-app are closing their browsers
without using the "logout"-Button in my web app. This button is associated
with an action-method which calls some important "clean-up"-methods. If the
users are simply closing / exiting their browsers this action-method is not
called, which causes some problems for the hole web-app.

So is it possible to associate this "logout"-method with the "exiting of the
web-browser"? Is there another specific method called if the user closes his
browser?

Greetings,
Hendrik
______________________________________________________________
Verschicken Sie romantische, coole und witzige Bilder per SMS!
Jetzt bei WEB.DE FreeMail: http://f.web.de/?mc=021193

Search Discussions

  • Broekelmann, Mathias at May 18, 2005 at 8:34 am
    Hi,

    I think your problem will not be solved even if it is possible to catch
    the close event of the browser. It is always possible that the
    connection between your app and the user is broken and the user can not
    call the logout method.

    Try using a javax.servlet.http.HttpSessionListener instance and
    implement your "clean-up" code in the sessionDestroyed method and
    register the class through your web.xml file.

    Mathias
    -----Original Message-----
    From: Hendrik Neumann
    Sent: Wednesday, May 18, 2005 10:20 AM
    To: users@myfaces.apache.org
    Subject: What is happening to the session if a user closes
    his browser?


    Hi everybody,

    I have big problems when the users of my web-app are closing
    their browsers
    without using the "logout"-Button in my web app. This button
    is associated
    with an action-method which calls some important
    "clean-up"-methods. If the
    users are simply closing / exiting their browsers this
    action-method is not
    called, which causes some problems for the hole web-app.

    So is it possible to associate this "logout"-method with the
    "exiting of the
    web-browser"? Is there another specific method called if the
    user closes his
    browser?

    Greetings,
    Hendrik
    ______________________________________________________________
    Verschicken Sie romantische, coole und witzige Bilder per SMS!
    Jetzt bei WEB.DE FreeMail: http://f.web.de/?mc=021193
  • Piepaolo Follia at May 18, 2005 at 8:35 am
    Hi Hendrik.
    When a user close his browser the session still lives on the application
    server. It'll be deleted by the garbage collector after a fixed delay
    (you can configure it - session life time - in any AS).
    Your problem is a common problem: you can resolve it simply using the
    finalize method
    (http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html#finalize())
    of a session bean. The finalize method is invoked by the garbage
    collector when the AS destroy your session. You can use it to do clean
    up operations.
    It's simple and almost clean.
    Hope this could help you.

    bye

    -- Pierpaolo

    in data 18/05/2005 10.20 Hendrik Neumann ha scritto:
    Hi everybody,

    I have big problems when the users of my web-app are closing their browsers
    without using the "logout"-Button in my web app. This button is associated
    with an action-method which calls some important "clean-up"-methods. If the
    users are simply closing / exiting their browsers this action-method is not
    called, which causes some problems for the hole web-app.

    So is it possible to associate this "logout"-method with the "exiting of the
    web-browser"? Is there another specific method called if the user closes his
    browser?

    Greetings,
    Hendrik
    ______________________________________________________________
    Verschicken Sie romantische, coole und witzige Bilder per SMS!
    Jetzt bei WEB.DE FreeMail: http://f.web.de/?mc=021193


    --
    Pierpaolo Follia
    Wave S.r.l. - Vai Benaco 24/B, Bedizzole (BS)
    Telefono: +39 030 687561
    Fax: +39 030 6875690
  • Hendrik Neumann at May 18, 2005 at 9:27 am
    Thank you very much for your answers Pierpaolo and Mathias. I have just implemented Mathias' solution with the Session-Listener and it works perfect!

    By the way: is it possivle to get the ip-address associated with a session? I have not found a method like getIPAdress() and the method myHttpSessionEvent.getSource() does also not contain the ip address. Is there another solution to get it, because I want to write something like "Session created for 127.0.0.1" in my logfile. Is it possible?
    __________________________________________________________
    Mit WEB.DE FreePhone mit hoechster Qualitaet ab 0 Ct./Min.
    weltweit telefonieren! http://freephone.web.de/?mc=021201
  • Piepaolo Follia at May 18, 2005 at 12:51 pm
    in data 18/05/2005 11.25 Hendrik Neumann ha scritto:
    By the way: is it possivle to get the ip-address associated with a session? I have not found a method like getIPAdress() and the method myHttpSessionEvent.getSource() does also not contain the ip address. Is there another solution to get it, because I want to write something like "Session created for 127.0.0.1" in my logfile. Is it possible?
    You can get it from the request: put a filter in the request chain and
    in the doFilter method see if the session is a new session:

    public void doFilter(ServletRequest request, ServletResponse response,
    FilterChain chain) throws IOException, ServletException {
    if(((HttpServletRequest)request).getSession().isNew()) {
    //Do your stuff here with request.getLocalAddr()
    }
    chain..doFilter(request, response);
    }

    bye

    --
    Pierpaolo Follia
    Wave S.r.l. - Vai Benaco 24/B, Bedizzole (BS)
    Telefono: +39 030 687561
    Fax: +39 030 6875690
  • Piepaolo Follia at May 18, 2005 at 12:58 pm

    in data 18/05/2005 14.46 Piepaolo Follia ha scritto:

    You can get it from the request: put a filter in the request chain and
    in the doFilter method see if the session is a new session:

    public void doFilter(ServletRequest request, ServletResponse response,
    FilterChain chain) throws IOException, ServletException {
    if(((HttpServletRequest)request).getSession().isNew()) {
    //Do your stuff here with request.getLocalAddr()
    }
    chain..doFilter(request, response);
    }
    Sorry...the method for getting the ip address from request is
    request.getRemoteAddr(), and not the local one! :-)

    --
    Pierpaolo Follia
    Wave S.r.l. - Vai Benaco 24/B, Bedizzole (BS)
    Telefono: +39 030 687561
    Fax: +39 030 6875690

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupusers @
categoriesmyfaces
postedMay 18, '05 at 8:22a
activeMay 18, '05 at 12:58p
posts6
users3
websitemyfaces.apache.org

People

Translate

site design / logo © 2019 Grokbase