• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to use Session Binders and LIsteners??

 
Ranch Hand
Posts: 227
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Manohar Karamballi
Ranch Hand
Posts: 227
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 227
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 227
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 227
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I donno how to handle event without using window.open()
 
reply
    Bookmark Topic Watch Topic
  • New Topic