tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mark <>
Subject getInitParameter() trouble
Date Wed, 03 May 2000 23:03:00 GMT
I think I am going to need a bit of spoon-feeding to get started, so
please bear with me.  I am an experienced sysadmin, but rather a novice
Java programmer, so I am quite confused on a few points.

I need some help putting together a correct CLASSPATH, because I'm
having trouble (re)compiling the examples, SnoopServlet in particular.
However, I am able to write, compile, and run simple servlets and JSP.

Also I am having trouble using getInitParameter().

I've included a lot of information that I hope will be helpful to track
down the problems.

Here's what I've got set up so far:

- Apache 1.3.12 on WinNT with Tomcat 3.1
- javac from Sun's JDK1.2.2
   - c:\jdk1.2.2\bin is in the PATH, before the WinNT directories
- CLASSPATH=c:\jdsk2.0\lib\jsdk.jar OR
     have been adequate to compile all my test servlets and JSPs, but
not SnoopServlet.

When I run /examples/servlet/snoop (which is really SnoopServlet.class):

Servlet init parameters:
   JdbcDriver = sun.jdbc.odbc.JdbcOdbcDriver
   dbURL = jdbc:odbc:movie

As expected, because web.xml contains:


I have a test servlet that contains a cut-and-pasted copy of the code
segment from SnoopServlet that lists the init params.  I attempt to
assign the init-params in the same web.xml file like this:


Note that these are in the same examples/WEB-INF/web.xml file, and all
the servlets are in the /examples/WEB-INF/classes directory. compiles fine, but when the servlet runs:

Internal Servlet Error:
	at TestServlet.doGet(, Compiled Code)

But this exception is thrown by exactly the same code segment that works
fine and retrieves the expected values in SnoopServlet.class:

	out.println("Servlet init parameters:");
	Enumeration e = getInitParameterNames();
	while (e.hasMoreElements()) {
	    String key = (String)e.nextElement();
	    String value = getInitParameter(key);
	    out.println("   " + key + " = " + value); 

I only tried the above after the segment below failed to work, with
another null pointer problem.

            String driver = getInitParameter("JdbcDriver");
            String dbURL = getInitParameter("dbURL");

As for the CLASSPATH problem, when I try to recompile

>>> Method getInitParameterNames() not found in
interface javax.servlet.ServletContext.
        Enumeration enum = context.getInitParameterNames();
                                                        ^ Method getInitParameter(java.lang.String) not
found in interface javax.servlet.ServletContext.
            Object value = context.getInitParameter(key);
                                                   ^ Method getServletName() not found in class
        out.println("Servlet Name: " + getServletName());
                                                     ^ Method getLocale() not found in interface
        out.println("Locale: "+ request.getLocale());
                                                 ^ Method getBufferSize() not found in interface
        out.println("Default Response Buffer: "+
                                                                       ^ Method isSecure() not found in interface
        out.println("Request Is Secure: " + request.isSecure());
                                                            ^ Method getContextPath() not found in interface
        out.println("Context Path: " + request.getContextPath());
                                                             ^ Method getAttributeNames() not found in interface
        Enumeration names = session.getAttributeNames();
                                                     ^ Method getAttribute(java.lang.String) not found
in interface javax.servlet.http.HttpSession.
            out.println("   " + name + " = " +
9 errors

Thanks in advance for any pointers.  Possibly I've just been staring at
all this for too long and cannot see the obvious.

Mark Kolmar
Manta Media Inc.

View raw message