I have a class which implements the ServletContextAttributesListener
interface. It has been registered as a listener in web.xml. The problem is,
Orion is creating two instances. Shouldn't there only be ONE instance of an
application level object?

Here is the class:

import javax.servlet.*;
public class Foo implements ServletContextAttributesListener {
    public void attributeAdded(ServletContextAttributeEvent ev) {
        System.out.println(this + " - Foo.servletContextAttributeAdded: " +
ev.getName());
    }
    public void attributeReplaced(ServletContextAttributeEvent event) {}
    public void attributeRemoved(ServletContextAttributeEvent event) {}
    public void test(){
         System.out.println(this + " - Foo.test");
    }
}

Here is a JSP that uses the class:

<jsp:useBean id="f" class="Foo" scope="application"/> (line 1)
<% f.test(); %> (line 2)

Here is the output:

Foo@7808b9 - Foo.servletContextAttributeAdded: f
Foo@4da23 - Foo.test

If you look at the memory addresses, you'll see that there are two
instances.

Is this a bug or am I misunderstanding something?

Dave Ford
Smart Soft - The Java Training Company
http://www.smart-soft.com


Reply via email to