What is the use of super.init (config) in servlets? Why it is required?

Questions by jayalakshmic   answers by jayalakshmic

Showing Answers 1 - 1 of 1 Answers

Amit Shah

  • Jun 12th, 2007
 

The init(ServletConfig) method is defined in the Servlet interface. It has been implemented by the GenericServlet class. The implementation of this init method in the GenericServlet just stores the ServletConfig object in some private variable so that when you use the method "getServletConfig()", it gives you the ServletConfig object.

If you override this init(ServletConfig) method but do not call "super.init(config)", then you need to take care of storing the ServletConfig object in your own member variable so that you can use it later in your servlet. This means you cannot retrieve it using "getServletConfig()" method.

As an alternative, you can simply override the "init()" method (without any parameters). In this case, you need not call "super.init(config)". If in this init method, you need the ServletConfig object, you can get it via "getServletConfig()" method. If you define this version of the init method, the GenericServlet's init(config) method will take care of calling your parameter-less init method.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions