• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

filter or listener

 
nimo frey
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a servlet-listener to obtain infos about the Users session.

How can I retrieve the ServletRequest from this listener to obtain e.g. IP-Adress (getLocalAddr).

Something like:



Is a filter better for this?
[ October 13, 2008: Message edited by: nimo frey ]
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Request is not available to the listeners because they don't get called on a per-request basis.

The filter is called on a per-request basis for all the URLs it is mapped to, so you do get the Request object, so it is a better place for this.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64994
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is it you are trying to do with this listener or filter?
 
nimo frey
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a listener who stores sessions beeing created (time of, HTTPSession) into a Map.

I also need the the methods of the ServletRequest.

So I ask, if I should only use a filter, as I can also get the Session (SessionCreationTime, HTTPSession,..) from the methods of ServletRequest.

For what do I need a listener, like:



when I can get the HTTPSession also from a filter?

Should I delete my Listener and only use a filter?

I am also considering to use the clickstream-api
http://www.opensymphony.com/clickstream/ and found out that the clickstream use both listener and filters:

# Start tracking click stream when users' sessions begin (via a Listener).
# Track information with each click the user makes (via a Servlet Filter).


Should I use this api? Or should I only use a filter?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64994
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You haven't really explained what you want to do with the session.
 
nimo frey
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to store the session in a Map with session related data (such as Creation Time, IP, etc). So I am unsure about the place where I should implement the map to get the data.

When I use the listener, then I can store the HTTPSession but has no access to ServletRequest-Object.

So I assume, that I need only a filter, because a filter has access to the HTTPSession and the ServletRequest-Object. Am I right?

Or do I need both -filter and listener? The clickstream-API needs both, but is it not enough to have only the listener? I mean, when a session is created, then I can get the (requested?) SessionObject from my filter and not only from my listener. Where lies the difference?
[ October 16, 2008: Message edited by: nimo frey ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64994
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why would you want to store a reference to the session? This is odd, uncustomary, and not very safe. You should never be storing references to container resources such as sessions, requests, responses and so on.

Again, what are you really trying to accomplish?
 
nimo frey
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hmm..odd?

Look at the Clickstream-Api (http://www.opensymphony.com/clickstream/).

I want to build a session-tracking-tool and do not understand for what using a listener, when a filter have access to anything that the filter has.
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Bear about storing sessions. If clickstream stores the session for what it does then it is poorly designed. It does not need to do it.

From the docs, the Filter is used to track a user's movement through the web site. It gets info for each request and stores it. Where it stores it is unimportant - possible in some user token inside the session or in a context-wide storage location mapped to a user.

The Session Listener is to track when a session ends. When the session ends (presumably user-log out) then the filter is used to send the tracked information into a log file. It could get that information out of the same storage that the filter uses - either from a token in the session, or from a context wide map.

In neither case do you need to store a reference to the session itself, and if clickstream is doing it then it shouldn't be looked at as normal procedure.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic