thanks in advance.,
eagerly waiting for your replies.,
pankaj vijay wrote:at this time there is no servletConfig object also. so you can use init(ServletConfig config) method to pass other servlets ServletConfig object.
I don't quite follow the logic behind this, but your code should neither call other servlet's init methods, nor pass around ServletConfig objects.
pankaj vijay wrote:you can use init(ServletConfig config) method to pass other servlets ServletConfig object.
that is what GenericServlet class do for you! . you no need to do this again. if you want to Override init then always use init()[Servlet version] .
public void init(ServletConfig config)
Called by the servlet container to indicate to a servlet that the servlet is being placed into service. See Servlet.init(javax.servlet.ServletConfig).
This implementation stores the ServletConfig object it receives from the servlet container for later use. When overriding this form of the method, call super.init(config).
This is what init(config) method is used, you can overwrite this method but then you will need to call the Super.init(config) method, because if you forget this then, I suppose the initialization process of your servlet will not complete properly, the servlet does not have access to the ServletConfig and the application throws a NullPointerException if you try to access it.
Instead there is another method
public void init()
A convenience method which can be overridden so that there's no need to call super.init(config).
Instead of overriding init(ServletConfig), simply override this method and it will be called by GenericServlet.init(ServletConfig config). The ServletConfig object can still be retrieved via getServletConfig().
Making a method final would be necessary if there would be a huge impact if someone tried overriding the method, if you look at what code is there in the init(config) method
there is nothing that one will miss or do after overriding as there is nothing one can do in the init method with respect to different JSP API/JSP implicit objects. Nothing is available so I think they thought if it is not going to be misused why even make it final. Though it throws an NullPointer but then thats trivial, not big enough problem to make a method final.
So the best practice is to use init() method and not init(config) method and forget final for these methods.
Read about final on Wiki and there are some links on the same page that talk about why and when to use final.
Finally, have a nice day!