aspose file tools*
The moose likes Servlets and the fly likes HttpSessionListener,HttpSessionAttributeListener Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "HttpSessionListener,HttpSessionAttributeListener" Watch "HttpSessionListener,HttpSessionAttributeListener" New topic
Author

HttpSessionListener,HttpSessionAttributeListener

Thamarai kannan
Greenhorn

Joined: May 05, 2009
Posts: 28
hi....Can any one explain the difference between HttpSessionListener VS HttpSessionAttributeListener?
Nicola Garofalo
Ranch Hand

Joined: Apr 10, 2010
Posts: 308
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?


Bye,
Nicola
Harpreet Singh janda
Ranch Hand

Joined: Jan 14, 2010
Posts: 317

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

Joined: May 05, 2009
Posts: 28
thanks will work out and see.............
Thamarai kannan
Greenhorn

Joined: May 05, 2009
Posts: 28
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

Joined: Apr 10, 2010
Posts: 308
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

Joined: May 05, 2009
Posts: 28
Thanks alot understood
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HttpSessionListener,HttpSessionAttributeListener
 
Similar Threads
Confusion on httpSession listeners
Chapter 6(Session Management) notes (HFSJ) for revision
what listeners don't need to register in DD
Are Session Activation Listeners configured in DD?
Context-param doubt