Hello all,
I tried to understand listerners with this code, but i discovered that i did't understand anything about listerers after i saw the output!
can anyone kindly explain to me why this happens :S
=========================
you have this scriptlet
<%
Dog a=new Dog();
Dog b=new Dog();
a.setName("popy");
b.setName("lolo");
session.setAttribute("a",a);
session.setAttribute("a",b);
session.removeAttribute("a");
%>
and following listeners...
public class Dog implements HttpSessionBindingListener
{
private
String name;
public void valueBound(HttpSessionBindingEvent event)
{
System.out.println("dog bound "+event.getValue());
}
public void valueUnbound(HttpSessionBindingEvent event)
{
System.out.println("dog unbound "+event.getValue());
}
public String toString()
{
return name;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
}
====================================
public class Session HttpSessionListener
{
public void sessionCreated(HttpSessionEvent se)
{
System.out.println("session created "+se.getSession().getId());
}
public void sessionDestroyed(HttpSessionEvent se)
{
System.out.println("session destroyed "+se.getSession().getId());
}
}
=================================================
public class SessionAtt implements HttpSessionAttributeListener
{
public void attributeAdded(HttpSessionBindingEvent se)
{
System.out.println("attribute added in session: "+se.getValue());
}
public void attributeRemoved(HttpSessionBindingEvent se)
{
System.out.println("attribute removed in session: "+se.getValue());
}
public void attributeReplaced(HttpSessionBindingEvent se)
{
System.out.println("attribute replaced in session: "+se.getValue());
}
}
==========
and this is the output
session created 6AAD1A8E522E94AFCE0254BF06897C3B
dog bound popy
attribute added in session: popy
dog bound lolo
dog unbound null
attribute replaced in session: lolo
dog unbound lolo
attribute removed in session: lolo