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: Setting context parameters with XML files?
Date Tue, 05 Sep 2000 16:58:49 GMT
brian.king@amd.com wrote:

> Is it possible to set context parameters using one of the .xml files?  If
> so, how is it done?
>
> Right now I'm using a servlet that loads on tomcat start-up and calls
> getServletContext().setAttribute(name, value);.
> This works, but seems kind of clumsy.
>

It is possible to set context *initialization parameters*, but not
attributes, in the web.xml file:

    <context-param>
        <param-name>MyName</param-name>
        <param-value>My parameter value</param-value>
    </context-param>

which you can read with:

    getServletContext().getInitParameter("MyName");

To initialize servlet context attributes, the most common technique is to
create a special initialization servlet and configure it to load on startup.
Then, set up the attributes you need in the init() method.

In the servlet 2.3 spec (public draft currently available at
http://java.sun.com/products/servlet), an additional technique called
application events is being added.  You will be able to register a class that
should receive notification when the web application is started up or shut
down, and you can configure your servlet context attributes there.

>
> Thanks in advance,
> Brian King

Craig McClanahan

====================
See you at ApacheCon Europe <http://www.apachecon.com>!
Session VS01 (23-Oct 13h00-17h00):  Sun Technical Briefing
Session T06  (24-Oct 14h00-15h00):  Migrating Apache JServ
                                    Applications to Tomcat



Mime
View raw message