wood burning stoves 2.0*
The moose likes Servlets and the fly likes How to use Session Binders and LIsteners?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to use Session Binders and LIsteners??" Watch "How to use Session Binders and LIsteners??" New topic
Author

How to use Session Binders and LIsteners??

Manohar Karamballi
Ranch Hand

Joined: Jul 17, 2001
Posts: 227
Hai All!
I am not understanding how to club Http Session Binding Event with it's listener. My task is to make an log entry when user is logged out of session or when session expires. while first one is easy to carry out second one seems to be a tough one.
Any help or code regarding usage of Session Listeners is appreciable.
Regards
Manohar
Raghav Sam
Ranch Hand

Joined: Apr 12, 2001
Posts: 412
Originally posted by Manohar Karamballi:
Hai All!
I am not understanding how to club Http Session Binding Event with it's listener. My task is to make an log entry when user is logged out of session or when session expires. while first one is easy to carry out second one seems to be a tough one.
Any help or code regarding usage of Session Listeners is appreciable.
Regards
Manohar

Make your class implement HttpSessionBindingListener and override valueBound() and valueUnbound(). Add an object of this class to the session ("binding"). In valueUnbound() write like this,

Now when the session expires, valueUnbound() will be automatically called and a log created.
Hope this helps.

------------------
Raghav.


Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind.<br />- Dr. Seuss
Manohar Karamballi
Ranch Hand

Joined: Jul 17, 2001
Posts: 227
Hai Raghav!
Thanks for ur reply. That worked out well for session time-out but still i have one problem. i.e when client exited session abnormally(say by clicking X in browser window..)
that valueUnbound is not getting triggered. What to do now? I have one more doubt regarding concepts. When client closed the Browser window is it not equilavent to terminating session?
Anticipating reply
TIA
Manohar
DC Dalton
Ranch Hand

Joined: May 28, 2001
Posts: 287
Im trying to do the exact same thing thing with a web site who's on type program & ran into the same problem as you are having. The only thing I can think of is to use a JavaScript where you can grab the window.close() event & run them thru a logout servlet that they should never even see! Im actually going to try it later this week so Ill let you how it works.
Raghav Sam
Ranch Hand

Joined: Apr 12, 2001
Posts: 412
Originally posted by Manohar Karamballi:
Hai Raghav!
Thanks for ur reply. That worked out well for session time-out but still i have one problem. i.e when client exited session abnormally(say by clicking X in browser window..)
that valueUnbound is not getting triggered. What to do now? I have one more doubt regarding concepts. When client closed the Browser window is it not equilavent to terminating session?
Anticipating reply
TIA
Manohar

You are right. When an user closes the browser window abnormally, session does not terminate automatically. For this you must check if there is an already active session by calling request.getSession(false) while logging in. If there is, then invalidate it. Once the old session is invalidated, valueUnbound will be automatically called. This works only if you have something like a 'login' servlet.
------------------
Raghav.
[This message has been edited by Raghav Sam (edited July 23, 2001).]
Manohar Karamballi
Ranch Hand

Joined: Jul 17, 2001
Posts: 227
Hai All!
I tried out in some different way using java scripts and it worked out. What i did was that i maintained one hidden field in my form with default value "N". When user clicked Submit i am setting it to "Y". On Unload of page i am calling unload script given below.
function unload()
{
if(document.InfoForm.isInvalid.value!="Y")
{
//URL rewriting
strUserID= document.InfoForm.UserID.value;
strIsInvalid= document.InfoForm.isInvalid.value;
strURL="Logout.jsp?UserID="+strUserID+"&isInvalid="+strIsInvalid;
window.open(strURL);
}
}
i am able to invoke JSP even when user abnormally logged out as unload script will be invoked everytime irrespective of manner the page gets unloaded.
Is there any drawback in this approach?
Suggestions are welcome.
Regards
Manohar
madhu gun
Greenhorn

Joined: Nov 21, 2001
Posts: 25
hi Manohar,
i have the same situation.i too am doing the same.I am using onunload property of the body object and a similar function and a flag like yours.hope u too are using the onunload property of the body object.But the problem is we I dont want the new window to open or appear.Any remedy!
regards,
madhu
Manohar Karamballi
Ranch Hand

Joined: Jul 17, 2001
Posts: 227
Hai!
There is better alternative for handling this situation without using Javascript at all and that is the one which i used in my dispatched code...
Use session time out concept,,
For further details goto
http://www.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=7&t=007242
Still u face any problems ...let me know..
Rgds
Manohar
madhu gun
Greenhorn

Joined: Nov 21, 2001
Posts: 25
hi Manohar,
Thanq.
The situation in my case is diffrent.I have seen the link.I had done that too.Indeed,I am continuing that.Session Time-out is No the case.User has got say two windows open parent and child.He closes the child window using X button.
Then I have to receive the message at server and release some of the Database connections.So I am using the onunload property(script)and the window.open method.
regards
madhu
Manohar Karamballi
Ranch Hand

Joined: Jul 17, 2001
Posts: 227
I donno how to handle event without using window.open()
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to use Session Binders and LIsteners??
 
Similar Threads
Order of Listener Notification
Handling Session TimeOut
HFSJ Mock Questions.
order of listeners
listener class