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.
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.
varun
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
mannam Haribabu chowdary
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
span style="font-style: italic;">//logic to write con,st objects
// logic to write release the resources
--------------------------
}
mukesh pandey
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
Praveen D
Feb 1st, 2013
It is possible to Override init() & destroy() methods in servelts
rekha
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 doesn’t get performed. As a result getServletConfig() will return null.
Why init(), destroy() can't be overridden in servlets?