You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Craig R. McClanahan" <cr...@apache.org> on 2001/09/02 07:05:22 UTC

Re: context-param

On Tue, 28 Aug 2001, Mills, Theo wrote:

> Date: Tue, 28 Aug 2001 13:41:07 -0500
> From: "Mills, Theo" <th...@twc.state.tx.us>
> Reply-To: tomcat-user@jakarta.apache.org
> To: "'tomcat-user@jakarta.apache.org'" <to...@jakarta.apache.org>
> Subject: context-param
>
> Anyone know how to access an application-wide context-param from a servlet?
>

The simplest way is to use a context parameter in your web.xml file:

  <context-param>
    <param-name>global-name</param-name>
    <param-value>This is the parameter value</param-value>
  </context-param>

which you can retrieve from a servlet by calling:

  getServletContext().getInitParameter("global-name");

NOTE:  There are rules you *must* follow about the order of elements in
your web.xml file -- see the Servlet Specification, which you can download
from:

  http://java.sun.com/products/servlet/download.html

Craig McClanahan