This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

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
Ranch Hand
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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!