aspose file tools*
The moose likes Servlets and the fly likes Filter vs Listener to keep track of session instances Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Reply locked New topic
Author

Filter vs Listener to keep track of session instances

nimo frey
Ranch Hand

Joined: Jun 28, 2008
Posts: 580
When do I need Filter and when, Listener?

In

http://www.jguru.com/faq/view.jsp?EID=1063899
it is said, to keep track of all session-instances, it s better to do that with filter than with listener (such as HTTPSessionListener).


Any suggestions?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61761
    
  67

When do you need the info?

A listener will fire when the event occurs. A filter is executed when a request whose URL matches its mapping is invoked.

Which makes the most sense for your scenario?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
nimo frey
Ranch Hand

Joined: Jun 28, 2008
Posts: 580

Which makes the most sense for your scenario?


hmm..good question:-)

Look at my topic http://www.coderanch.com/t/321300/EJB-JEE/java/destroy-sessionContext-EJB.

I want to get the session-instance when it s created by the user.

I have solved this via an HTTPSessionListener storing all sessions in a map in the application-scope.

But how can I delete a particular Session via this listener?

Do I need the HTTPSessionEvent for that? Should I do that with the HTTPAttributeListener? Or with HttpSessionBindingEvent or HttpSessionBindingListener?

I have no clue how to retrieve and delete a particular session.

With session.invalidate() only the actual session will be destroyed.

I need something like the deprecated HttpSessionContext in which I can get a particular ID and delete it.

Any Ideas?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61761
    
  67

Well that appears to be a completely different question than "when do I used filters vs. listeners?"

I'd recommend changing the topic title accordingly.
nimo frey
Ranch Hand

Joined: Jun 28, 2008
Posts: 580
I d guessed that I can achieve this scenario with filters..it was not clear. Okay it seems it s better to use listeners. no ideas?
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

I am keeping the conversation in your other thread where it is more appropriate... no need to split the conversation.


Steve
 
wood burning stoves
 
subject: Filter vs Listener to keep track of session instances