On Thu, 8 Mar 2001, Craig Smithpeters wrote:
> I have had the problem of servlets that are loaded on startup being
> loaded again (init method firing again) on their first access by a
> client. This issue has been discussed a lot on the list over the
> last year and I have not seen a solution that would work for me.
>
> I have found that if you set the <servlet-name> entry equal to the
> <servlet-class> entry in the web app's web.xml file that it will
> solve the problem.
>
> Evidently, Tomcat is determining what servlets are loaded by
> checking the servlet-name entries and not the servlet-class entries.
> I think this should be considered a bug.
Actually, if I understand you correctly, this is the known, desired
(and useful) behavior, and is all spelled out in the spec (I don't
know if there's one section of the spec that talks about it, but
search for "definition" and "instance"). That is, when you define a
servlet, it is the servlet-name that defines the servlet, not the
servlet-class. You can have multiple servlet definitions involving
the same servlet-class and different servlet-name's, and they are
considered distinct (i.e. different init-param's, different servlet
instances, and hence init will be called multiple times, as you are
experiencing). As to which servlet definition is used, it all depends
on what servlet-name is specified in the URL (and if any
servlet-mapping's are defined in the servlet definition). Also, this
can happen even when you only have one servlet definition, because
calling the servlet using the servlet-class directly (i.e. not the
servlet-name) is distinct as well. For example, if in webapp myapp
you define a servlet with servlet-name foo and servlet-class
com.my.foo, the following lead to distinct servlet instances:
http://www.my.com/myapp/servlet/foo
http://www.my.com/myapp/servlet/com.my.foo
and will cause init to be called twice on the underlying servlet-class.
Milt Epstein
Research Programmer
Software/Systems Development Group
Computing and Communications Services Office (CCSO)
University of Illinois at Urbana-Champaign (UIUC)
[EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]