Yesterday, the init() method of a servlet of mine started to be called
twice. The hash code of the servlet object proved that there were two
separate instances of the servlet. The archives mention some causes of this
situation, but mine was caused by another one. I'm posting this here in case
it's of help to anyone else.
>From the archives:
"From: Larry Isaacs
Subject: RE: Servlet's init() method being called twice?
Date: Fri, 9 Nov 2001 09:18:09 -0500
This can occur if you have a web application under the auto-served
"webapps" directory and also create a context for that same web
application but with a different path, i.e.
<Context path="/otherpath" docBase="webapps/mywebapp" ...
You would get the same webapp served as "/mywebapp" and
"/otherpath", hence two calls to your servlet's init(),
one for each context.
Larry"
In my case, I first executed the servlet using the name contained in the
<url-pattern> of a <servlet-mapping>. in web.xml; the second time the
servlet was executed it was referenced by its full name relative to the
webapps directory. When I changed the second reference to also use the name
from the <url-pattern> the problem went away.
It appears that the lesson here is that a given servlet should always be
accessed using the same URL, or else Tomcat will treat each different URL as
a reference to a "different" servlet.
Regards, Gord Tomlin
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>