Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP 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
Posts: 42968
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