This week's book giveaway is in the Python forum.
We're giving away four copies of Python Continuous Integration and Delivery and have Moritz Lenz on-line!
See this thread for details.
Win a copy of Python Continuous Integration and Delivery this week in the Python forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

init() methods in Generic Servlet  RSS feed

 
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

i am a little confused my book says class GenericServlet implements Servlet interface. it further says if i have to override the init() method
it is better to call super.init() while overidding the init() method.

I cannot understand which of the two init()'s method is refering to when it says overide. the overloaded init() of GenericServlet or init method of the ServletInterface.

Hope i am making sense.


regards
[ May 16, 2006: Message edited by: faisal usmani ]
 
Author
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Always override the no-argument init() method... the reason is that the GenericServlet class implements the init(ServletConfig) to save the ServletConfig locally in an instance variable (it can later be obtained by invoking getServletConfig()). The init(ServletConfig) method in GenericServlet then delegates to the no-argument init() which is the one you should implement.

There is no need to invoke super.init() from your init() implementation; indeed, the purpose of this method is to prevent such necessities; from the API documentation:

public void init()
A convenience method which can be overridden so that there's no need to call super.init(config).



Hope that helps!
 
faisal usmani
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanx charles.
 
Did you ever grow anything in the garden of your mind? - Fred Rogers. Tiny ad:
Become a Java guru with IntelliJ IDEA
https://www.jetbrains.com/idea/
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!