reset password
Author Message
ashoush
Posts: 25
Posted 23:16 Oct 10, 2009 |

Hi,

When I override the init() method of a servlet, I need to put        

super.init(config) ; 

inside the method, otherwise it throws an NPE exception when I use the getServletContext() method. However in the class video I see that this is not happening. Anybody knows what might be different on my server that make this happen?

Thanks.

 

cysun
Posts: 2935
Posted 12:34 Oct 11, 2009 |

Eclipse's servlet wizard auto-generates the skeleton for "public void init(ServletConfig config) throws ServletException", which is wrong. You should override "public void init() throws ServletException" instead (i.e. simply remove the argument of the init method generated by Eclipse).

See http://java.sun.com/products/servlet/2.5/docs/servlet-2_5-mr2/javax/servlet/GenericServlet.html for the difference between init() and init(config).