Paul Philion wrote:

> Greetings all...
>
> I consistantly get the following exception when trying to use Servlet.log() in the 
>latest version of the JWSDK. If I use ServletContext.log(), everything seems to work.
>
> Error: 500
>
> Internal Servlet Error:
>
> java.lang.NullPointerException
>         at javax.servlet.GenericServlet.getServletContext(GenericServlet.java:201)
>         at javax.servlet.GenericServlet.log(GenericServlet.java:319)
>         at RoutingServlet.doGet(RoutingServlet.java:76)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:715)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:840)
>         at com.sun.web.core.ServletWrapper.handleRequest(ServletWrapper.java:155)
>         at com.sun.web.core.Context.handleRequest(Context.java:414)
>         at com.sun.web.server.ConnectionHandler.run(ConnectionHandler.java:139)
>
> It appears as if something is not initialized correctly in the GenericServlet. Is 
>this something I (as a developer) should be initializing, or is this just a bug?
>
> - Paul Philion
>

The usual cause of this is an incorrectly coded init(ServletConfig config) method -- 
you need to call super(config) at the beginning of this to cause the pointer to the
ServletConfig (and associated ServletContext) to be saved.  The details are in the 
JavaDoc documentation.

Because this was happening to so many people, a new version of the init() method was 
added in the 2.1 API.  You can define an init() method with no arguments, and use
getServletConfig() inside it to access the initialization parameters, without having 
to worry about calling super() -- although it is generally good practice to do so when
you are subclassing something and overriding an existing method.

Craig McClanahan

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to