File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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: 13036
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()
jQuery in Action, 3rd edition