• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

valueUnbound - when called?

 
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?
 
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic