• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

init() method

 
Ranch Hand
Posts: 304
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is adviced to override init() method but if you are overriding init(ServletConfig) then we need to call super.init(ServletConfig). Why?

I learned that init() is called in init(ServletConfig) of super class so that it can give servletness to the servlet. If that is the case then we can override any init method and then call super.init() so that the servletness of the servlet is gained.

Please let me know if i am unclear.

Thanks for your answer(s)!
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Atul Sawant:
It is adviced to override init() method but if you are overriding init(ServletConfig) then we need to call super.init(ServletConfig). Why?



the important reason to call super.init(ServletConfig) is that it sets the ServletConfig object in the servlet. If you overide init(ServletConfig)without calling super.init(SC) You would not be setting the ServletConfig object.
 
Atul Sawant
Ranch Hand
Posts: 304
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Clifton. One more basic question on this. Which method does the container implicitly calls if you have not overrided any init() method from superclass? init() or init(ServletConfig)?
[ April 10, 2007: Message edited by: Atul Savant ]
 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Container calls both the method. It will call init(confi) followed by init(). If you don't override init(), the default implementation will be called and the default implementaion of init() does nothing.
The container calls init() from inside init(config) method.
[ April 10, 2007: Message edited by: Tridib Samanta ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic