• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Need for init() method

 
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 294
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 294
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
What's that smell? I think this tiny ad may have stepped in something.
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic