• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HFS Page 827 question 53 ???

 
Raju Sri
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

On page 827 of HFS for question 53 is "What type of listener could be used to log the user name of a user at the time that she logs into a System ?".

I thought the answer is "A".Because using HttpSessionListener we can findout when the user is logged in to the System. But in the book the answer is given as "C".I don't clearly understand how HttpSessionAttributeListener is useful in loogging the username.

Can some body pls explain clearly why "C" is correct and "A" is not correct as per HFS.

Regards
Raju
 
Anthony Watson
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Raju,

If you look at the methods in HttpSessionListener, you will see 1) sessionCreated 2) sessionDestroyed. The sessionCreated method will execute immediately after the user's session was created, but before any data was put into the session. So, if you want to log information about a user, you can't do it in the sessionCreated method, because there is no user data in the session at the time the method is executed.

On the other hand, the HttpSessionAttributeListener class has a method with the following signature:

public void attributeAdded(HttpSessionBindingEvent se)

This method is fired when data is added to the user's session, such as the user's security related information. So, the attributeAdded method is a perfect place to log such information.
 
Raju Sri
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Anthony for clear explanation.

Regards
Raju
 
Arut Jothi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about using other AttributeListerners? On the same question in HFS, there is a ServletContextAttributeListerner is a choice. SO why should I use HttpSessionAttributeListener alone to log. I would do it at Context level because sessions can be multiple for the same user. So if admin user wants to publish currently logged users list How do I do that? Please help me on this.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic