You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Marcel van Beurden (ETM)" <Ma...@etm.ericsson.se> on 2001/04/24 09:20:42 UTC

Getting context-param in servlet problems...ARGH

Hi there,

I'm going slightly crazy. I want to get a parameter from the <context-param> section from my web.xml in my servlet. But I can't get it to work.

I quote from the example web.xml in the Tomcat docs:

<quote>
  The values actually assigned to these parameters can be retrieved in a servlet or JSP page by calling:

    String value = getServletContext().getInitParameter("name");

  where "name" matches the <param-name> element of one of these initialization parameters.
</quote>

When I copy and paste this line of code into my init() method of my servlet I get a compilation error:

"MyServlet.java": Error #: 300 : method getInitParameter(java.lang.String) not found in interface javax.servlet.ServletContext at line 35, column 40

I'm really confused now. My web.xml is below. Help !

Best regards,
Marcel

My web.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
    "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">

<web-app>
    <context-param>
        <param-name>jdbcDriverName</param-name>
        <param-value>org.gjt.mm.mysql.Driver</param-value>
    </context-param>
    <context-param>
        <param-name>jdbcConnectString</param-name>
        <param-value>jdbc:mysql://localhost/db</param-value>
    </context-param>

    <servlet>
        <servlet-name>
            servlet1
        </servlet-name>
        <servlet-class>
            Servlet1
        </servlet-class>
    </servlet>

    <servlet>
        <servlet-name>
            servlet2
        </servlet-name>
        <servlet-class>
            Servlet2
        </servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>servlet1</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>

    <servlet-mapping>
        <servlet-name>servlet2</servlet-name>
        <url-pattern>/log/*</url-pattern>
    </servlet-mapping>

</web-app>