This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet's init() method

 
dolly shah
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am little confuse about Servlet's initialization. I am not getting when init() is invoked & when init(SservletConfig) is invoked? Which method helps to initialize Servlet? Can anyone please explain?
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The container controls the life of Servlet. When a Servlet is first needed, the container needs to start the Servlet's life. It does this by calling the init(ServletConfig) method as defined by the Servlet interface.

The class GenericServlet realized that you're probably safer not having to worry about setting the ServletConfig object in the init method. It's a bit of a pain having to worry about it and most people won't need to touch it. So GenericServlet added an overloaded convenience method for init.

How can it do this and still set the ServletConfig object? Well, it might look something like this:
 
dolly shah
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


So this code executes every time when the Servlet is initialized by container before handles any client & after constructor runs. Please correct me if I am wrong.
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, the init is the first thing that gets called after the constructor. I don't have any of my SCWCD books in front of me but I seem to recall they all explain this.
 
dolly shah
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Marc.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic