Hi to all Please anybody tell me Why is there an init()method ? In other words ,why is not the constructor enough for initializing a servelet? Please explain in detail and with example if possible.
This is given in HFSJ at page no. 102 but i am unable to understand it(means not got it).
SCJP 5.0(75%), SCWCD 5.0(88%)
Aditya Singh
Ranch Hand
Joined: Mar 06, 2008
Posts: 62
posted
0
So that we can happly override it, without bothering to call super.init(ServletCOnfig)
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35222
7
posted
0
While Aditya's answer is correct, it's only half the story.
The method that is part of the Servlet interface is init(ServletConfig config). Its purpose it to pass a ServletConfig object to the servlet (which is needed to perform number of things in the servlet). Since an interface can't specify that there needs to be a constructor with this parameter, it was made a method.