Why not? We can override these two methods also. We can override init() method for connecting to the database or some other resources. The init() method called by the container only once ,when the servlet has been loaded into the memory. You can override the destroy method to release the resources. When we stopped our server the destroy method will call by the container. But the service method will call each and every time the request came.
Login to rate this answer.
We can override the init() and destory() methods in servelets.
The init() method called by the container only once ,when the servlet has been loaded into the memory. We can override init() method for connecting to the database or some other resources.We can override the destroy method to release the resources.
Login to rate this answer.
varun
Answered On : Jul 31st, 2012
bcz init() and destroy() methods can call only once in the life-cycle of a servlet due to which we can make only one object during the session , thats why it is better than CGI bcz in that we have to call init() method every time when we request the servlet
Login to rate this answer.
mannam Haribabu chowdary
Answered On : Aug 27th, 2012
int() and destroy() methods are override in servlet class surly 100% no problum
but int() is not a life cycle method .it is a convenenance method Here we write initilising logics like conncetion obj and statement objects
and destroy() are also one time execution block when programmer raising an event i.e shut down server like that
Code
abstract class Generic servley
{
public void inti(ServletConfig cg)
{
----------------------------
-----------------------
init()
------------------------
--------------------
}
servletconfig getServletConfig()
{
return cg;
}
destroy()
{
--------------
}
class Hello extends GenericServlet
{
init()
{
---------------------------------
--------------------------------//logic to write con,st objects
--------------------------------
}
public void destroy()
{
------------------------------// logic to write release the resources
--------------------------
}
Login to rate this answer.
mukesh pandey
Answered On : Nov 4th, 2012
init() is possible to override () if you have initialization code like database connection or registering your self.
service() method look the request and response. Determine the Http method (get,post). Override not possible
Login to rate this answer.
Praveen D
Answered On : Feb 1st, 2013
It is possible to Override init() & destroy() methods in servelts
Login to rate this answer.
rekha
Answered On : Feb 13th, 2013
Can override init & destroy .
People used to make mistakes by overriding inti(ServletConfig).
Because if we override and forget to call super.inti(ServletConfig) then default actions doesnt get performed. As a result getServletConfig() will return null.
Login to rate this answer.