tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mark <m...@mantamedia.com>
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
  CLASSPATH=c:\jsdk2.1\server.jar;c:\jsdk2.1\servlet.jar
     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:

>>>
        <init-param>
            <param-name>JdbcDriver</param-name>
            <param-value>sun.jdbc.odbc.JdbcOdbcDriver</param-value>
        </init-param>
        <init-param>
            <param-name>dbURL</param-name>
            <param-value>jdbc:odbc:movie</param-value>
        </init-param>
<<<

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:

>>>
    <servlet>
        <servlet-name>
            parmTest
        </servlet-name>
        <servlet-class>
            TestServlet
        </servlet-class>
        <init-param>
            <param-name>JdbcDriver</param-name>
            <param-value>sun.jdbc.odbc.JdbcOdbcDriver</param-value>
        </init-param>
        <init-param>
            <param-name>dbURL</param-name>
            <param-value>jdbc:odbc:movie</param-value>
        </init-param>
    </servlet>
<<<

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.

TestServlet.java compiles fine, but when the servlet runs:

>>>
Internal Servlet Error:
java.lang.NullPointerException: 
	at
javax.servlet.GenericServlet.getInitParameterNames(GenericServlet.java:1
68)
	at TestServlet.doGet(TestServlet.java, 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); 
	}
	out.println();
<<<

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 SnoopServlet.java:

>>>
SnoopServlet.java:39: Method getInitParameterNames() not found in
interface javax.servlet.ServletContext.
        Enumeration enum = context.getInitParameterNames();
                                                        ^
SnoopServlet.java:42: Method getInitParameter(java.lang.String) not
found in interface javax.servlet.ServletContext.
            Object value = context.getInitParameter(key);
                                                   ^
SnoopServlet.java:64: Method getServletName() not found in class
SnoopServlet.
        out.println("Servlet Name: " + getServletName());
                                                     ^
SnoopServlet.java:75: Method getLocale() not found in interface
javax.servlet.http.HttpServletRequest.
        out.println("Locale: "+ request.getLocale());
                                                 ^
SnoopServlet.java:76: Method getBufferSize() not found in interface
javax.servlet.http.HttpServletResponse.
        out.println("Default Response Buffer: "+
response.getBufferSize());
                                                                       ^
SnoopServlet.java:106: Method isSecure() not found in interface
javax.servlet.http.HttpServletRequest.
        out.println("Request Is Secure: " + request.isSecure());
                                                            ^
SnoopServlet.java:111: Method getContextPath() not found in interface
javax.servlet.http.HttpServletRequest.
        out.println("Context Path: " + request.getContextPath());
                                                             ^
SnoopServlet.java:129: Method getAttributeNames() not found in interface
javax.servlet.http.HttpSession.
        Enumeration names = session.getAttributeNames();
                                                     ^
SnoopServlet.java:132: Method getAttribute(java.lang.String) not found
in interface javax.servlet.http.HttpSession.
            out.println("   " + name + " = " +
session.getAttribute(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.

Mime
View raw message