tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject Getting the values of <context-param>s defined in web.xml ??
Date Fri, 20 Jul 2001 16:35:24 GMT

    I set up a servlet web.xml based on the sample web.xml provided with
the Tomcat 3.2.2 distribution.  I left in the example definition of the
<context-param> ( shown below ).  I added code (shown below) to the
servlet to print the names of all <context-param>s.  I didn't see any of
the <context-params> I added to my web.xml and I didn't see the example
either. I should point out that defining <init-params> on a per servlet
basis worked as described and is my current work-around.

    Adding to the confusion is the example in the Tomcat 3.2.2 web.xml.
The example says:
"The values actually assigned to these (<context-param>) parameters can
be retrieved in a servlet or JSP page by calling:"
    String value = getServletContext().getInitParameter("name");
However, the javax.servlet.ServletContext interface does not have
getInitParam( String ) method.  And, to add to the confusion, there IS a
getInitParam ( String) method in the javax.servlet.ServletConfig

    Since this sort of thing is done all of the time I'm sure I'm just
missing something really simple but after several hours of trying
everything I can think of I still can't get those damned
<context-params>.  Can anyone shed some light on this situation?

    Thanks in advance,

    Typical <context-param> definition in web.xml from Tomcat:

            <!-- all other web.xml contents omitted -->


    Servlet code to print <context-param> names:
      Enumeration contextParams =
getServletConfig().getInitParameterNames() ;
      while ( contextParams.hasMoreElements()) {
       String p = (String)contextParams.nextElement() ;
       System.out.println( "config param=" + p);

    I also tried:
      Enumeration contextParams =
getServletContext().getAttributeNames() ;
      while ( contextParams.hasMoreElements()) {
           String p = (String)contextParams.nextElement() ;
           System.out.println( "contextParams param=" + p);

View raw message