You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-user@jakarta.apache.org by "Karr, David" <Da...@wamu.net> on 2004/01/26 22:06:26 UTC

Cactus141: Trying to test servlet with "log()" calls, no ServletConfig

I'm trying to build tests for a servlet that calls "log(...)" in the
servlet code.  When it calls this, it's throwing an exception like this:

java.lang.NullPointerException
	at
javax.servlet.GenericServlet.getServletContext(GenericServlet.java:204)
	at javax.servlet.GenericServlet.log(GenericServlet.java:321)

I narrowed this down to realizing that the ServletConfig was null.  How
is this normally supposed to be set in this environment?

I'm using Cactus1.4.1, JDK1.4.2, and Tomcat4.1.29.

RE: Cactus141: Trying to test servlet with "log()" calls, no ServletConfig

Posted by Vincent Massol <vm...@pivolis.com>.
Hi David,

Yes, that's normal. It's because you haven't initialized your servlet.
You  need to call:

MyServlet servlet = new MyServlet();
servlet.init(config); <---- important line

[...]

Thanks
-Vincent

> -----Original Message-----
> From: Karr, David [mailto:David.Karr@wamu.net]
> Sent: 26 January 2004 22:06
> To: cactus-user@jakarta.apache.org
> Subject: Cactus141: Trying to test servlet with "log()" calls, no
> ServletConfig
> 
> I'm trying to build tests for a servlet that calls "log(...)" in the
> servlet code.  When it calls this, it's throwing an exception like
this:
> 
> java.lang.NullPointerException
> 	at
>
javax.servlet.GenericServlet.getServletContext(GenericServlet.java:204)
> 	at javax.servlet.GenericServlet.log(GenericServlet.java:321)
> 
> I narrowed this down to realizing that the ServletConfig was null.
How
> is this normally supposed to be set in this environment?
> 
> I'm using Cactus1.4.1, JDK1.4.2, and Tomcat4.1.29.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: cactus-user-help@jakarta.apache.org