• 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
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Need for init() method

 
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a question why in the KS book about the need for the init() ... that is why do we need the init() method even after the constuructors are executed??...
i guess the need is something related to the servlet context and config availability ..
could someone explain in short ... so that i can learn more about it???
 
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

why do we need the init() method even after the constuructors are executed??...



init(ServletConfig) is the life cycle method of servlet and is called by the web container on the servlet.You cannot call it yourself at your own will to get the servlet config object.so you have to wait for this method to be called if you want to use ServletConfig object.

Thanks,
Raj
 
Sony Agrawal
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
right... so that is the only purpose of the init() ?? i.e to give access to the servlet config and context??
 
raj malhotra
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes and then you can initalize your servlet further using the information from Servlet config or Servlet context.
Note still we have chance to initialize the servlet as service method will not run unless init method is complete.
 
You're not going crazy. You're going sane in a crazy word. Find comfort in this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic