• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ContextAttributeListener and equals()

 
peter greaves
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all
i seems to me from my testing that my listener is not called if an attribute is added to the context with the same name and value as an existing attribute - so if i have this in doGet:

and i have this in attributeAdded where event is the ServletContextAttributeEvent :

i will only see the log output once - the first time the attribute is set. i guess that equals() is coming into play here? brings up the subject of the right place for attributes of varying scopes.
[ November 02, 2003: Message edited by: peter greaves ]
 
Dumitru Husleag
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need a listener record in deployment descriptor like this:
<listener>
<listener-class>scwcd.MyServletContextListener</listener-class>
</listener>
where you replace the class name with yours (fully qualified class name).
 
cyril vidal
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Peter,
If you add add an attribute to ServletContext with the same name as one already existing, that is the method void attributeReplaced(ServletContextAttributeEvent scae) of javax.servlet.ServletContextAttributeListener that is called, not void attributeAdded(ServletContextAttributeEvent scae) from the same interface.
This last method (the one you're also mentionning in your thred) is just used for the first time an attribute is set to the ServletContext.
That's why you code works only for the first time..
Please refer to .the javadoc
Hope this helps,
Regards,
Cyril
[ November 16, 2003: Message edited by: cyril vidal ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic