tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ansgar W. Konermann" <>
Subject GenericServlet.getServletConfig buggy?
Date Fri, 23 Feb 2001 03:00:17 GMT
Hi all,

I (still) have a problem with the context of a servlet.

Within a class derived from HttpServlet (nop.Receiver), this
is my doGet method:

    public void doGet(HttpServletRequest rq, HttpServletResponse rs) 
        throws IOException, ServletException 
        PrintWriter out = rs.getWriter();
        out.println("<P>Chat Receiver</P>\n");

        ServletConfig myConfig = getServletConfig();
        out.println("myConfig == " + myConfig + "<br>"); // debug output
        theContext = getServletContext();
        out.println("theContext == " + theContext + "<br>"); // debug output

	// ...


It gives me the following output when I call the servlet:


Chat Receiver

myConfig == null

Error: 500

Location: /trial/servlet/Receiver

Internal Servlet Error:

        at javax.servlet.GenericServlet.getServletContext(
        at nop.Receiver.doGet(
        at javax.servlet.http.HttpServlet.service(
        at javax.servlet.http.HttpServlet.service(
        at org.apache.tomcat.core.ServletWrapper.doService(
        at org.apache.tomcat.core.Handler.service(
        at org.apache.tomcat.core.ServletWrapper.service(
        at org.apache.tomcat.core.ContextManager.internalService(
        at org.apache.tomcat.core.ContextManager.service(
        at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(
        at org.apache.tomcat.service.TcpWorkerThread.runIt(
        at org.apache.tomcat.util.ThreadPool$


Please note that myConfig == null and that the following call to 
getServletContext fails with a NullPtrXcpt. From the source code
of GenericServlet I can see that getServletContext is merely

According to the Servlet API, Servlet.getServletConfig(),

"Implementations of this interface are responsible for storing
the ServletConfig object so that this method can return it.
The GenericServlet class, which implements this interface,
already does this."

To me, this looks like the implementation I am using is *not*
storing the ServletConfig (which was previously passed to init),
since it returns null. Therefore, GenericServlet.getServletContext
must fail (since it relies on getServletConfig).

Is this a bug or am I just too blind to see my mistake?
Any help would be greatly apreciated.

(Using Tomcat Web Server/3.2.1 (JSP 1.1; Servlet 2.2; Java 1.3.0;
Linux 2.2.16 i386; java.vendor=Sun Microsystems Inc.)


Best regards,

Ansgar W. Konermann

View raw message