Obtaining init parameter(s) from ServletConfig

Discussions

Web tier: servlets, JSP, Web frameworks: Obtaining init parameter(s) from ServletConfig

  1. Is there a way to obtain the init parameter to a given resource from the ServletConfig or any other facade? I am trying to obtain the init param to a filter within a Struts Action and am wondering if there is a cleaner way to do it, other than using request/session attributes.

    Thanks!
  2. You could always retrieve and parse the web.xml file itself. Other than that, I don't know how you could do this; as a rule, servlets to do not have access to each other's configuration information.

    If your config values are truly global, you ought to define them as context parameters:

    <web-app>
      <context-param>
        <param-name>help-email</param-name>
        <param-value>help at domain dot com</param-value>
      </context-param>
      <!-- Other configuration -->
    </web-app>

    Then you can retrieve them from the ServletContext:

    servletContext.getInitParameter("help-email");