This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
On one of the web sites I read "After the servlet object is instantiated, the container must initialize the servlet before it can handle requests from clients. Initialization is provided so that a servlet can read persistent configuration data, initialize costly resources (such as JDBC connections), and perform other one-time activities. The container initializes the servlet instance by calling the init method of the Servlet interface with a unique (per servlet declaration) object implementing the ServletConfig interface."
So to initialize the ServletConfig object. Is that the only purpose,isn't it? Other things we can do with the Constructor also like initializing the member variable of Servlet class etc.
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35240
7
posted
0
Welcome to JavaRanch.
I think you're overlooking the "... and perform other one-time activities" part. Initializing the ServletConfig object is just part of it.
You can do initialization of member variables from within init() method. As already mentioned in one of the answers that one should avoid using member variables to avoid threading problems. But, you are always welcome to use mutable member variables as they don't cause any threading problem and you can initialize them in your init() definition.
Initializing DB Connections (either physical or logical) in init() will probably be implemented using member variables only :-)