I have a doubt regarding the constructor in servlet
I have learnt that we can write a no-arg constructor in servlet and this costructor is called by the container.
I want to know that can we write servlet initialization code in this constructor instead of writing it init() method.
ramakrishna kulkarni wrote:I have learnt that we can write a no-arg constructor in servlet and this costructor is called by the container.
I want to know that can we write servlet initialization code in this constructor instead of writing it init() method.
Servlet initialization code belongs in the init() method not in the constructor.
I agree that its a bad practice to write a constructor in servlet class.
My question is still not answered, Is it legal or is it possible to write initialization code in servlet constructor.
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35438
9
posted
0
It is not illegal in the sense that the judicial system of whatever jurisdiction you're in will come after you if you do it.
As to whether it's possible, how have you tried to prove or disprove it?