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: Global Parameters
Date Fri, 04 Aug 2000 18:32:12 GMT
See below.

Rene Duettra wrote:

> >The easiest way to do this is to use context initialization parameters,
> >rather than servlet initialization parameters.  I don't have the Servlet
> >2.2 spec in front of me, but it's probably <context-param> or something
> >like that.
> >
> >
> >In the servlet, you retrieve such a parameter like this:
> >
> >    String paramValue =
> >      getServletContext().getInitParameter("paramName");
> >
> >Craig McClanaha
> -------------------------------------------------------
>
> I used it this way. But how about accessing a servlet which has
> no init parameters BEFORE the servlet, which has one.
> If you try this:
>  String paramValue =
>       getServletContext().getInitParameter("paramName");
>
> paramValue will be null...
>

In other words, you want to use a servlet-specific value if it's there, and
the global value if not?  That's really easy -- just add an "if":

    String paramValue =
      getServletConfig().getInitParameter("paramName");
    if (paramValue == null)
        paramValue =
          getServletContext().getInitParameter("paramName");

The Apache JServ behavior relating to global servlet properties is not in the
servlet spec, so you won't be able to rely on it as a portable feature.  The
logic stated above is portable across any container that implements the 2.2
or later spec.

Craig



Mime
View raw message