Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » Tomcat Users »

Init parameters in default context

Keith Hankin

2004-04-23

Replies:

I am trying to specify init context parameters in the default context in server.xml as follows:
<Context path="" docBase="ROOT" debug="0">
   <Parameter name="configDir" value="C:\config" override="false"/>
</Context>
This is the only context I have listed in server.xml. Then I have my Servlet class as follows:
public abstract class JdbcServlet extends HttpServlet
{
   public void init(ServletConfig config) throws ServletException
   {
      super.init(config);
      String configDir = getServletContext().getInitParameter("configDir");
      System.out.println("configDir = " + configDir);
   }

   ...

}
This prints out: "configDir = null" rather than "configDir = C:\config" as I would expect.

It only works if I specify the parameter in a more specific context as follows:
<Context path="/mycontext" docBase="/mycontext" debug="0">
   <Parameter name="configDir" value="C:\config" override="false"/>
</Context>
I have tried this with Tomcat 4.1.30 and 5.0.19 with the same results.

©2008 junlu.com - Jax Systems, LLC, U.S.A.