initializing and Finalizing a Session
1 posts in topic
Flat View  Flat View

Posted By:   Daniel_Baylon
Posted On:   Thursday, November 14, 2002 10:20 AM

Somebody knows if exists a initialization / finalization process for Session

I found jspInit and jspDestroy methods, but only works on Pages, I'm looking for equivalents methods for Sessions, something like sessionInit and sessionDestroy.

I appreciate some help

Best Regards

Re: initializing and Finalizing a Session

Posted By:   Joost_Schouten  
Posted On:   Sunday, November 17, 2002 08:03 PM

make a small bean/class that implements the HttpSessionBindingListener interface. Place the folowing methods in this new class:

public void valueBound(javax.servlet.http.HttpSessionBindingEvent httpSessionBindingEvent) {
//your binding (init) code here;

public void valueUnbound(javax.servlet.http.HttpSessionBindingEvent httpSessionBindingEvent) {
//your unBinding (destroy) code here

Instanciate this class and set it in your session with
 session.setAttribute("myListner", thisNewListnerClassInstance);

The thisNewListnerClassInstance.valueBound() method will than be called. When you unbind the instance with session.removeAttribute("myListner"), or wait untill the sesison is invalidated, the thisNewListnerClassInstance.valueUnbound() method is called. This is fairly simmilar to the well known init() and destroy() methods of your servlets.

Good luck,


About | Sitemap | Contact