• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HttpSessionListener,HttpSessionAttributeListener

 
Thamarai kannan
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi....Can any one explain the difference between HttpSessionListener VS HttpSessionAttributeListener?
 
Nicola Garofalo
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at the methods to override in the classes that implement those interfaces.

What do you see?

If one of your classes is an HttpSessionListener what should it be able to do?

If one of your classes is an HttpSessionAttributeListener instead?

if in your servlet you write this line



Which of the two interfaces is awakened? And which of the method to be implemented is executed?
 
Harpreet Singh janda
Ranch Hand
Posts: 317
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HttpSessionListener Listens to Create and destroy events of a session.
HttpSessionAttributeListener listens to add, remove and replace events of any attribute in session.
 
Thamarai kannan
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks will work out and see.............
 
Thamarai kannan
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ..got the difference in case of httpsessionlisenter

1.It will be listening in case of session obect creation and invalidate .

In case of httpsessionattributelistener

1.It will be monitored for each attribute action.
 
Nicola Garofalo
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you write a class that implements HttpSessionListener it will be stay there in silent in your container until the session is created or invalidated. But when a new session is created it will wake up and do whatever you wrote in the method



When the session expires or if it's invalidated the other method is called:



When i write



your class couldn't care less about it, because no session was created nor destroyed.

Who cares about the line above is HttpSessionAttributeListener

In that line you set an attribute in your session, then if you wrote a class that implements HttpSessionAttributeListener, a method of that class will be invoked.

But there's more

if the attribute AWAKE_MESSAGE was set for the first time the method called is



Now if you want to set another value for the AWAKE_MESSAGE session attribute you can write:



another method will take care of this change. It's



if you're sick of those messages, you remove that attribute from the session



The last method of the HttpSessionAttributeListener interface will catch this event. It is



I hope this helps



 
Thamarai kannan
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks alot understood
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic