Obtaining init parameter(s) from ServletConfig


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.

  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:

        <param-value>help at domain dot com</param-value>
      <!-- Other configuration -->

    Then you can retrieve them from the ServletContext: