Discussions

Web tier: servlets, JSP, Web frameworks: developed a chat with JSP/beans -stuck up somewhere need Help

  1. Hello,
    I have made a HTML chat using JSP/Beans and everything is working fine in chat.What i am not able to work out is how to remove a user from the chatusers list as soon as the user closes the browser.i didn't find anything in javascript to trap the closing of browser.
    Another solution in my mind is if I can trap the expiry of sessions then as soon as the session expires then the session user will be removed from the users list.But don't know how to trap that as when the user closes the browser his session automatically invalidates.
    I am using a bean chatUsers storing all the chat users.
    and in jsp i have used application scope to make this bean data of application level so that user added from any browser remain in chatusers list(or I can declare static Vector chatUsers in chatUsers class)If I remove the application scope then only current chat user is shown,so i have made the scope to application so that all users share same bean object and data will be persistent.But once a user name is stored then when the user closes the browser and leaves the chat,still it is showing his name in users list beacuse it is of application level and recreates the list only when the application starts again -there I stuck up how to trap this closing of browser and remove that user from the chatUsers list stored in the bean.
    On sites i have seen as soon as the user closes the browser he is removed from the users list,but i'm not able to work out how to implement this ,where should i call the removeUser function and when to call it.
    Any immediate help will be highly appreciated.
    <jsp:useBean id="chatUsers" scope=application class="chat.chatUsers"/>
    Thanks In Advance
    Regards
    Rashmi
  2. hi rashmi

    i got ur problem, but can u tell where ur storing all the
    users, do u have written any methods for adding/removing.

    pl mail ur bean code , i will try my best to help
    sri_murthy at hotmail dot com

    thanks
  3. need help[ Go to top ]

    hi rashmi..
     this is sumeet ..can u give me the soource code of chat program

    i will be grateful to u..it is very urgent...
     thanks..
     bye take care
  4. I have faced the same problem which you are facing .. The solution which I adopt was some thing like this.

    1. I have created a session listner class that listen the active session object after a specified amount of time. That time can be set in the server configuration side.

    2. For user logging, I have created hash table .. not vector. Using hash is little more easy than Vector.

    3. I did not know how to capture the close window event so I have adapted this solution. I don't know whether there is a window close event or not ?

    4. I have changed my application to look like log in and log out type. It helps me in activity monitoring of the user as well. Like which room he joined or from which room he was kicked or banned. All that information is traced on activity monitoring.

    5. When ever the session lisnter indicate the time up and user did not do any activity then just log that user out of the application. I am sure that you have security check , whether a non log in person can enter into website.

    Well, that's all. I don't know whether this solution is optimized or understandable to you. I think , I made myself clear.

    shozi
  5. chat using bean[ Go to top ]

    hi rashmi.
    can u give me ur source code for bean..so that i can do rnd and come up with a solution...even thopugh u have a solution..plz send me the cofde it is urgent
    ..plz mail me at sumeet.saraf@rediffmail.com
  6. Implement the HttpSessionBindingListener interface in your class.When the user closes the browser,the session expires and the valueunbound() is called.Get the session(using getSession) and remove the corresponding userId from your Vector.It might be better to use a Hastable rather than a vector to store the info.
                -Prakash
  7. Hello everybody,
    Thanks for ur responses.I have found onUnload() function to trap the closing of browser.
    Called the removeUser()javascript function (placed the code of removing the user in this function)from onUnload() and get the things running.
    <body onUnload()="removeUser()">
    now when the user closes the browser code written in removeUser() gets executed and the user name picked up from the session is removed from the bean by calling the removeChatUser(chatName) bean function.


    Thanks
    Rashmi
  8. <html>
    <body onLoad="closing=true" onUnload="if (closing) window.open('C:/testJava/test2.htm','newwin');">
    CLOSE IT TO OPEN
    </html>

    if u think its fine...just reply to my mail id...else if u got the soln do mail me that...



    thnx
    regds
    Subhash.K