• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Listeners Vs Filters

 
Sandeep Vaid
Ranch Hand
Posts: 392
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It says that we can use filters to track the user request but all these we can do by listeners also so why filters ?
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What kind of listener would you use that gets activated by an incoming request?
 
Sergio Tridente
Ranch Hand
Posts: 329
Java Linux Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may use ServletRequestListener.
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With filters you can use the Chain of Responsibility pattern whereas I do not think this could be accomplished with the listener.

The filters' implementation of Chain of Responsibility allows you to wrap the request or response using the Decorator pattern. This is something else that the listener does not allow you to do.

Oh, and I think the listener can only be run when a request is created or destroyed. This means it can not be configured to run during a forwarding of a request - but as I recall it is possible to configure listeners to run on any of the different kinds of dispatching on a request.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic