Howdy,
This point comes up every couple of weeks.  Searching the archives will
reveal more details, but I'll summarize some points below:

- Webapps are supposed to be stand-alone, container-independent.
- All the information about the environment that you can get in a
portable fashion is contained in the servlet context object.
- Anything else, e.g. the location of various directories or files
outside your webapp, should be provided by you manually in your
deployment descriptor.
- server.xml is tomcat-specific, does not have a dtd/schema, can never
have one, and is not guaranteed to contain a <Context tag for your
webapp.

- The path can be retrieved from a ServletRequest (getContextPath()).
It typically corresponds to the display-name element in your web.xml, if
you specify one.  The display-name of the context is therefore available
from the servlet context during initialization: getServletContextName().

- The docBase is very container-dependent.  You don't want to depend on
it for anything.  Instead, include the relevant directory as a
context-param.  Consider the example of deploying a .war file to an
Oracle 9iAS server: the war file stays packaged and where's your
docBase? ;)

Obviously, you could hack your way into parsing server.xml and getting
Context elements and all their attributes.  But the approach would not
be portable, and is not even likely to work with future versions of
tomcat.

Yoav Shapira
Millennium ChemInformatics


>-----Original Message-----
>From: Sridhar Devulkar [mailto:[EMAIL PROTECTED]]
>Sent: Thursday, December 12, 2002 1:10 PM
>To: Tomcat Users List (E-mail)
>Subject: Accessing the Context tag attributes of server.xml ...
>
>Hello,
>
>I am trying to get the application url (path) and the docBase value
that I
>have provided in my <Context> tag in the server.xml file from my
servlet
>code.  The context that I have given is like this ..
>
><Context path="/admin"  debug="9" docBase="modules/admin/public"
>reloadable="true">
>             <Logger className="org.apache.catalina.logger.FileLogger"
>                  prefix="admin_log." suffix=".txt"
>                  timestamp="true"/>
></Context>
>
>I somehow need to ge the "path" and the "docBase" values without
issuing a
>Http request.  Actually, I have a servlet that perform all my
application
>initialization and that point, I need to get these values.
>
>Please help.
>
>Thanks.
>
>Sridhar.
>
>--
>To unsubscribe, e-mail:   <mailto:tomcat-user-
>[EMAIL PROTECTED]>
>For additional commands, e-mail: <mailto:tomcat-user-
>[EMAIL PROTECTED]>


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to