Hello,
I'd like to track values put in the session with HttpSessionBindingListener
interface. So I have built my class that implements this interface.
- - - - - - - - - - - - - - - - - - - - - - - -
package bean;
import javax.servlet.http.*;
import javax.servlet.*;
import java.util.*;
public class MyListener implements HttpSessionBindingListener
{
ServletContext context;
public MyListener(ServletContext context)
{
this.context = context;
}
public void valueBound(HttpSessionBindingEvent event)
{
System.out.println(" *** [valueBound] *** Someone just bound my listener to a session!");
}
public void valueUnbound(HttpSessionBindingEvent event)
{
System.out.println(" *** [valueBound] *** Someone just unbound my listener to a session!");
}
}
- - - - - - - - - - - - - - - - - - - - - - - - - -
When I bind an istance of this class to the session the listener signals a valueBound to the session...
session.putValue("bindings.listener",new bean.MyListener(getServletContext()));
*** [valueBound] *** Someone just bound my listener to a session!
but other elements added to the session aren't tracked....
session.putValue("key1","value1");
session.putValue("key2","value2");
I need to issue again:
session.putValue("bindings.listener",new bean.MyListener(getServletContext()));
but this is not what I want...I just want to capture in the listener every value that's added to the session.
How can I achieve it?
Thanks
Francesco
Discussions
Web tier: servlets, JSP, Web frameworks: How to track session elements with HttpSessionBindingListener
-
How to track session elements with HttpSessionBindingListener (2 messages)
- Posted by: fmarchioni fmarchioni
- Posted on: April 17 2001 09:22 EDT
Threaded Messages (2)
- How to track session elements with HttpSessionBindingListener by sneha sharma on April 17 2001 11:01 EDT
- How to track session elements with HttpSessionBindingListener by Nicky Eshkenazi on April 17 2001 11:18 EDT
-
How to track session elements with HttpSessionBindingListener[ Go to top ]
- Posted by: sneha sharma
- Posted on: April 17 2001 11:01 EDT
- in response to fmarchioni fmarchioni
If you want to track each object bound to the session, then each object should implement this interface.
The other solution is you can get session.getAttributeNames().
This will give you the names of all objects bound to the session at the time of the call.
Regards,
Sneha -
How to track session elements with HttpSessionBindingListener[ Go to top ]
- Posted by: Nicky Eshkenazi
- Posted on: April 17 2001 11:18 EDT
- in response to sneha sharma
Take a look at the follwoing article:
http://www.onjava.com/pub/a/onjava/2001/04/12/listeners.html
Nicky