This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Method called during servlet initialization

 
P. Jain
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am studying from 2 books i.e Head first Servlets and Jsp and SCWCD Kit by Hanumant Deshmukh.

My problem is that one book says that init(servletconfig) is called during initialization and other book says that init() method is called.

I just want to confirm which method is called?
 
Shruthi Karthick
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Both the methods are called during servlet initialization only.

init(servletConfig) is called first.
init() is called from within init(servletConfig).
We can override init() for putting our own servlet initialization code.
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The servlet container can't call init(), because it is not part of the Servlet interface. init() is a method of GenericServlet, so it doesn't necessarily exist (because you're free to create servlets that do not extend GenericServlet or its subclass HttpServlet).

This kind of information is generally -and specifically in this case- part of the javadocs.
 
P. Jain
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply. My doubt has been cleared.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic