causes a call of the valueUnbound(...) of the previous instance of X and a call of the valueBound(...) of the new instance of X.

3. the next

causes a call of the valueUnbound(...) of the instance created in step 2. The new session attribute object, which is a type of String, does not implement the HttpSessionBindingListener interface, so there is call to the valueBound(...) function.

That is all.

Gabriel

kishore chitturi
Ranch Hand

Joined: Nov 28, 2004
Posts: 50

posted Nov 29, 2004 09:27:00

0

Hi Gabrial,

Thank you for giving such a nice explanation.

Regards kishore

kishore chitturi
Ranch Hand

Joined: Nov 28, 2004
Posts: 50

posted Nov 29, 2004 09:39:00

0

Hi Gabril,

But according to u, the output should be BUBBUBB(valubeBound,valueUnbound,valueBound,valueUnbound,valueBound).

But the outpur is BBUBUB(valueBound,valueBound,valueUnbound,valueUnbound).

The valueBound method must be called before the object is made available via the getAttribute method of the HttpSession interface. The valueUnbound method must be called after the object is no longer available via the getAttribute method of the HttpSession interface.

So in step 1 ( after First setAttribute method call ) the servlet prints "B", then in next step this SHOULD print "UB" as this get unbound. But the valueBound method of the next step will be called first, and then the valueUnbound method of first will be called.

That's why is the result.

If you put one more similar call to setAttribute, then the result will be B B UB B UB UB

Ha! I have it at last... The answer given is 'BBUBUB'. I too thought that it should be 'BBUBBUBUB'... but if you look closely at the question (original post), its class X that implements the listener - so there is no printout produced for the binding of "x" or the final unbinding of "key"

So:

outputs B

outputs B again, then UB

outputs UB, and thats it, the binding event of attribute "x" isn't listened for by anything, nor is the final removeAttribute();