This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes overriding init() and destroy() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "overriding init() and destroy()" Watch "overriding init() and destroy()" New topic

overriding init() and destroy()

Bob Moranski
Ranch Hand

Joined: Nov 22, 2000
Posts: 177
Hi, why is it that when we override init(aServletConfig) we have to have super.init(aServletConfig) but when we override destroy we do not have to have super.destroy()?
Sean MacLean
Ranch Hand

Joined: Nov 07, 2000
Posts: 621
I think it's simply because the parent servlet ussually has some of it's own intiallization to do. When you override it, you have to make sure that you allow it to do what it needs to by calling super. The destroy method, however, doesn't inherently do anything so it doesn't matter if you prevent the parent for running it's destroy by overriding it and not calling super.
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 12761
When you override
init(ServletConfig conf)
if you don't call super.init( conf )
then your servlet context does not get initialized correctly. You will get a null when you try to later access the config. This is a fairly common newbie mistake.
Bob Moranski
Ranch Hand

Joined: Nov 22, 2000
Posts: 177
Thank you guys very much!
I agree. Here's the link:
subject: overriding init() and destroy()
Similar Threads
Servlet's init() and destroy() method and constructors
Significance of Start() and Stop() methods
destroy method and synchronization
JSP Page source - Doubt?
The World of Servlet