• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

listeners problem!

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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



 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What result did you expect?
 
Walid El-Sewaify
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wonder why Binding listener took place before SessionAttribute listeners? what's the order of excution of listeners then??
why first dog unbound returns null while the second returns the dog name?

in attributeReplaced method, is there a way to get reference to the object that has been replaced?
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic