Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

about Listener's question

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I meet with this question in a mock exam.

"which interface must a class implement so that instances of the class are notified after ANY object is added to a session"

In my opinion is an ambiguous question because the word "ANY" in the question.
Right?


Thanks.
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not an ambiguous question. The answer is HttpSessionBindingListenr, this will notify the objects whenever an object of class is being added or removed from session.
 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My guess is the answer is an HttpSessionAttributeListener.

A Binding listener will only be notified when that listener object itself is bound.
[ June 12, 2008: Message edited by: Jan Sterk ]
 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Jan Sterk:
My guess is the answer is an HttpSessionAttributeListener.

A Binding listener will only be notified when that listener object itself is bound.

[ June 12, 2008: Message edited by: Jan Sterk ]



Hi you are perfectly right it's the HttpSessionAttributeListener & not the HttpSessionBindingListener ........
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If there is a HttpSessionAttributeListener declared in the DD,
then the call back methods like attributeAdded() / attributeReplaced() etc
will be called on this registered HttpSessionAttribute Listener.

If you want a particular object to be notified when it is added to the
HttpSession, the the class of this object should implement HttpSessionBindingListener.

So, HttpSessionBindingListener is the right answer.

Regards, Srinu
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"which interface must a class implement so that instances of the class are notified after ANY object is added to a session"

Its HttpSessionBindingListener since container has to notify the instance of class
 
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
HttpSessionBindingListener is the correct answer to this:
As specs says: "It Causes an object to be notified when it is bound to or unbound from a session. The object is notified by an HttpSessionBindingEvent object."
Here bound and unbound itself mean added or removed.
 
Jan Sterk
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Say you have this code:

Integer object = new Integer( 123 );
request.getSession().setAttribute( object );

Will it trigger a notification of any HttpSessionBindingListener, or a notification of HttpSessionAttributeListeners?
 
    Bookmark Topic Watch Topic
  • New Topic