You're looking for <init-param>. You can add these parameters to any
filter or servlet, or at the top-level for the entire webapp, and get
them when the filter or servlet runs (or any time you can get an
instance of the ServletContext which represents the webapp).
The usual way of doing this is to create a ServletContextListener which
implements the init() method, grabs the values from the <init-param>
parameters, and stuffs them into the "application" scope. Although this
is typically called the "application", you get it like this:

public void contextInitialized(ServletContextEvent sce)
{
    ServletContext application = sce.getServletContext();

    String myParam = application.getInitParameter("my-param");

    application.setAttribute("myParam", new Integer(myParam));
}

You can pretty much do anything you'd like at this point.

Hope that helps,

-chris

Hey Chris,

Awesome, I do in fact use param-name and param-value (init-param). So, I understand I have to make an addition to web.xml like:

<init-param>
     <param-name>variableName</param-name>
     <param-value>variableValue</param-value>
</init-param>

However, I'm not exactly sure what I'm supposed to do after this. I see that your code accounts for non-String variables by binding an object to the param-name (via setсttribute()), but I'm not sure of a couple of things. Where would this code go that gets and sets the value, so that it would only run once collectively for all users (not once per user)? More specifically, would this be executed during a restart of Tomcat? If so, how (by what class/method)?

Thanks for your quick response.  Your help is greatly appreciated.

-Ryan

Reply via email to