tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Abraham Fathman" <>
Subject RE: server.xml - context parameter question
Date Tue, 30 Apr 2002 07:31:59 GMT

I haven't done this before but I thought that it might help you out.

Instead of using the server.xml you could try adding your variables as
system properties. I believe you can do this by creating a
file in your bin directory. Here you can set an environmental variable

The catalina scripts should call this setenv script which will set the
JAVA_OPTS env variable. Then your code should be able to get this
property from the System.getProperty("dbserver") line.

Just a thought. Hope it helps,


-----Original Message-----
From: Tom Bednarz [] 
Sent: Tuesday, April 30, 2002 3:18 AM
To: Tomcat User List
Subject: server.xml - context parameter question


I have a problem in initializing my web application. The application
stores all of its configuration parameters in a database table. My
application has an initialization servlet which loads beside other
things the configuration. Initially this is done in the init method,
over time it is periodically done in a separate thread.

The problem is, that I need to compose a JDBC connect URL. One of the
components of this URL is the name or IP address of the database server.
This information cannot be put in the web.xml of the web application
since it depends on the runtime environment and cannot be pre-defined at
development time. To access the configuration information in the
database I need this JDBC connect URL. So I was looking for a
possibility to define parameters OUTSIDE my web application.

I found a context tag under the host tag in the server.xml file. The
TOMCAT documentation says:

 --------  snip ------------------------
You can configure named values that will be made visible to the web
application as servlet context initialization parameters by nesting
<Parameter> elements inside this element. For example, you can create an
initialization parameter like this:

<Context ...>
  <Parameter name="companyName" value="My Company, Incorporated"

This is equivalent to the inclusion of the following element in the web
application deployment descriptor (/WEB-INF/web.xml):

  <param-value>My Company, Incorporated</param-value> </context-param>

but does not require modification of the deployment descriptor to
customize this value.

-------------- end --------------------------

So I did the following:

<Context path="/MyWebapp" docBase="MyWebapp" debug="0"
     <Parameter name="DBServer" value="MyDatabaseServer"
override="false"/> </Context>

In the init() method of my initialization servlet (preload=1) I did the

        for (java.util.Enumeration e = config.getInitParameterNames();

where config is the ServletConfig object which is a parameter of the
HttpServlet.init(..) method. I expected to find the name DBServer as a
parameter name but it does NOT appear. Only those parameters defined in
the web applications web.xml file appear!

Could anybody explain me what I am doing wrong? What happens to context
entries in the server.xml file if the named context is NOT YET installed
e.g. is in the webapps directory as .war file?

Any help would be greatly appreciated.


To unsubscribe:   <>
For additional commands: <>
Troubles with the list: <>

To unsubscribe:   <>
For additional commands: <>
Troubles with the list: <>

View raw message