• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

valueUnbound - when called?

 
Manikandan Jayaraman
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Got this question in one mock.

Which statements are correct about object implementing HttpSessionBindingListener interface?

1) valueBound method will be called before the object is accessible through getAttribute method
2) valueBound method will be called after the object is accessible through getAttribute method
3) valueUnbound method will be called before the object is removed from the session
4) valueUnbound method will be called after the object is removed from the session

I thought Answers are 1 and 3. But test says 1 and 4. When is the valueUnbound method called.

I felt it should be called before the object is removed from session, so that it can exercise some of its effects on the session, by setting some state/flag et al.

Can someone explain?
 
Mv Caraiman
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Servlet 2.4 - SRV.7.4 Binding Attributes into a Session" says :

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

Your question is related to valueUnbound(). I think it make sense to be called after the object is no longer available via getAttribute(). Otherwise, a servlet could call it after valueUnbound() was called, which, IMHO, make valueUnbound() meaningless.
 
Manikandan Jayaraman
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Kama! Got your point.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic