You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Mike Erickson <ME...@PureEdge.com> on 2001/06/15 21:49:36 UTC
root context
hi, I have a servlet that I want to map to the root context, I removed
ROOT.war and copied my war file (foo.war) to the webapps folder and
added the following to server.xml:
<Context path=""
docBase="webapps/foo"
crossContext="false"
debug="0"
reloadable="false" >
</Context>
I can now access the servlet by hitting localhost/servlet/servletname
but I can also still access the server by hitting
localhost/foo/servlet/servletname, since the war is still in the webapps
folder, tomcat still automatically loads the context.. this is what I
expected, but I've noticed in servlet.log that the servlet init occurs
twice, once for the root context and once for the "foo" context, this is
not good.. so I thought that if I disable autoloading the foo context
would not init unless someone hit it (which is fine with me) so I set
<load-on-startup> to 0 within the web.xml file inside my war file,
restarted and I still see both context's running the init, even though I
expected to see none..
so is this the way to use the root context? and how can I not have 2
instances of the servlet running?
have I missed any other tricks when using the root context?
thanks
Mike Erickson
Re: root context
Posted by Dmitri Colebatch <di...@ozemail.com.au>.
Robert/Mike:
Putting
> > <Context path=""
> > docBase="webapps/foo"
> > crossContext="false"
> > debug="0"
> > reloadable="false" >
> > </Context>
in your server.xml is optional if your app is in the webapps directory
as tomcat will automatically deploy webapp/appname in a context of
appname. By putting the above in your server.xml file, you are
instructing tomcat to create a "" context with the app at
"webapps/foo". This however doesn't stop tomcat from loading apps in
the webapps directory. The first thing I do with a tomcat install is
clean the webapps directory, and then create my apps using the Context
tag in server.xml, with the files for the app sitting outside my webapps
directory.
for eg, my directory structure is:
$TOMCAT_HOME/bin
/conf
/lib
/logs
/work
/webapps <-- empty directory
/webapps.noautomount <-- where I put my apps
and then have the following:
<Context path=""
docBase="webapps.noautomount/foo"
crossContext="false"
debug="0"
reloadable="false" >
</Context>
in my server.xml. Alternatively, you can have the docBase attribute
point anywhere in the directory structure, and reference it relative to
$TOMCAT_HOME.
hope this helps
cheesr
dim
Re: root context
Posted by Robert Schweng <hy...@multiplayer.ch>.
hi,
i also had this problem.
i really dont know why its loaded twice
but my suggestion is to put the code in the service method of the servlet
which is really called only 1 time per session.
this is what i did.
cheers
hype
----- Original Message -----
From: Mike Erickson <ME...@PureEdge.com>
To: Tomcat-User (E-mail) <to...@jakarta.apache.org>
Sent: Friday, June 15, 2001 9:49 PM
Subject: root context
> hi, I have a servlet that I want to map to the root context, I removed
> ROOT.war and copied my war file (foo.war) to the webapps folder and
> added the following to server.xml:
>
> <Context path=""
> docBase="webapps/foo"
> crossContext="false"
> debug="0"
> reloadable="false" >
> </Context>
>
> I can now access the servlet by hitting localhost/servlet/servletname
> but I can also still access the server by hitting
> localhost/foo/servlet/servletname, since the war is still in the webapps
> folder, tomcat still automatically loads the context.. this is what I
> expected, but I've noticed in servlet.log that the servlet init occurs
> twice, once for the root context and once for the "foo" context, this is
> not good.. so I thought that if I disable autoloading the foo context
> would not init unless someone hit it (which is fine with me) so I set
> <load-on-startup> to 0 within the web.xml file inside my war file,
> restarted and I still see both context's running the init, even though I
> expected to see none..
>
> so is this the way to use the root context? and how can I not have 2
> instances of the servlet running?
> have I missed any other tricks when using the root context?
>
> thanks
> Mike Erickson
>
>
>
>
>