Rob Shaw wrote:
> I'm seeing a behaviour that suggests instantiation of servlets
> due to an invocation via a "servlet-mapping" or via the
> InvokerServlet (/servlet) are handled differently.
>
> More specifically, given that I've set up a Context for
> the path "/foo", and within that context, I've mapped
> "/some" to SomeServlet.
>
> If I make a request to http://localhost/foo/some, I can
> see the creation of an instantiation of SomeServlet.
> But, if I also make the request to
> http://localhost/foo/servlet/SomeServlet, I see an additional
> creation of an instance of SomeServlet.
>
> Is this an intentional behaviour or a bug?
> (Note: I have servlet reloading enabled)
>
> According to Servlet 2.2 Spec:
>
> > 3.2 Number of Instances
> > By default, there must be only one instance of a servlet
> > class per servlet definition in a container.
> > ...
>
> > 3.3.1 Loading and Instantiation
> > ...
> > It is important to note that there can be more than one
> > instance of a given Servlet class in the servlet
> > container. For example, this can occur where there
> > was more than one servlet definition that utilized a
> > specific servlet class with different initialization parameters.
> > ...
>
> Does the above two usage scenarios constitute a
> different "servlet definition"?
>
Yes.
The concept of an "invoker" servlet (i.e. the "/servlet/*" handler) is
not in the servlet specification at all (which only considers <servlet>
to be a servlet definition), but is commonly implemented in servlet
containers. What happens is, the first time you invoke a servlet via
/servlet/xxxxx, a new servlet definition is created dynamically. The
dynamically created servlet definition will have its own ServletConfig
structure with no servlet initialization parameters.
>
> Thanks,
> Rob.
Craig McClanahan