Why is it that the below servlet throws a null pointer exception when the init(ServletConfig config) is overridden instead of init() ?
Thanks, -SkD
Gabriel Forro
Ranch Hand
Joined: Apr 16, 2004
Posts: 59
posted
0
Hi,
the HttpServlet has a private member (type of ServletConfig). This private member is initialized in the init(ServletConfig) method. The getServletName() calls the ServletConfig's getServletName() function, so it uses the private member (which is null, if it is not initialized).
If You override this function, make sure do it as it follows:
Gabriel
Ture Hefner
Greenhorn
Joined: Nov 14, 2004
Posts: 18
posted
0
Right. If you override the init(ServletConfig sc) method in a Servlet, you must still call the overridden method in order to initialize the instance varible that keeps a handle to the ServletConfig. However, you use the "super" keyword to do this, not "base":