tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <Craig.McClana...@eng.sun.com>
Subject Re: <context-param> problems
Date Sat, 01 Apr 2000 19:22:18 GMT
Patrick Clark wrote:

> I am having a problem using the <context-param> tag within my web.xml file
> of my new wepp application.
>
> I want to be able to tell every servlet the value of a parameter that
> indicates the location of a configuration file.  This configuration file
> includes important information about the database connection and such.
>
> >From my servlet I am trying to get the init parameters with this java:
>
>       String s = this.getInitParameter("ConfigFile");
>
> Here is my web.xml from within my SimpleApp/web-inf directory:
>
> <?xml version="1.0" encoding="ISO-8859-1"?>
>
> <!DOCTYPE web-app
>     PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
>     "http://java.sun.com/j2ee/dtds/web-app_2.2.dtd">
>
> <web-app>
>   <context-param>
>     <param-name>ConfigFile</param-name>
>     <param-value>C:\configuration\config.txt<param-value>
>   </context-param>
> </web-app>
>
> I get no parameters.
>
> Am I using this correctly?  Is this what I should do to pass information to
> every servlet in my web app?
>

Context parameters become initial parameters of the servlet context, not of
each individual servlet.  Try this instead:

    String s =
      getServletContext().getInitParameter("ConfigFile");

>
> Thanks,
> Patrick
>

Craig McClanahan



Mime
View raw message