3 Replies Latest reply on Apr 8, 2004 6:01 PM by Peter Luttrell

    getServletContext() throwing a NullPointer?

    Peter Luttrell Newbie

      I'm trying to get my webapp that works perfectly with JBoss3.2.1 (with Jetty) to work with JBoss3.2.3 with Jetty 4.2.14.

      When i execute the following line of code in the doPost method of a servlet, i get a NullPointerException:

      System.out.println( "TEST: getServletContext()=" + getServletContext());

      Here's the stacktrace:

      Exception StackTrace: java.lang.NullPointerException
      at javax.servlet.GenericServlet.getServletContext(GenericServlet.java:204)
      at com.emsystem.web.MainController.doPost(MainController.java:104)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:356)
      at org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:294)
      at org.mortbay.jetty.servlet.Dispatcher.dispatch(Dispatcher.java:201)
      at org.mortbay.jetty.servlet.Dispatcher.forward(Dispatcher.java:133)
      at com.emsystem.arch.struts.EMSystemActionServlet.service(EMSystemActionServlet.java:52)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:356)
      at org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:294)
      at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:567)
      at org.mortbay.http.HttpContext.handle(HttpContext.java:1776)
      at org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplicationContext.java:514)
      at org.mortbay.http.HttpContext.handle(HttpContext.java:1726)
      at org.mortbay.http.HttpServer.service(HttpServer.java:879)
      at org.jboss.jetty.Jetty.service(Jetty.java:456)
      at org.mortbay.http.HttpConnection.service(HttpConnection.java:790)
      at org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:952)
      at org.mortbay.http.HttpConnection.handle(HttpConnection.java:807)
      at org.mortbay.http.SocketListener.handleConnection(SocketListener.java:196)
      at org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:289)
      at org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:487)

      When i execute the same code in 3.2.1, i get the following result:

      10:49:25,484 [PoolThread-8] INFO [STDOUT] TEST: getServletContext()=org.mortbay.jetty.servlet.ServletHandler$Context@b8f675

      I've seen others on the web complaining about this problem. In all cases it seams to be caused by overriding the init( ServletConfig config ) method in the servlet, but not calling super.init(context). In my case i do override it, but DO call super.init()...the config sent into the init method is NULL.

      Does anyone have any ideas as to what is causing this? Or how to fix it?

      thanks.
      .peter