Thursday, September 15, 2005

why do we have init method ?
After all why can't we make use of servlet constructor for initilization ?

You can't make use of the constructor because the container calls it and therefore you can't pass any parameters to the constructor. Also at the point the constructor is called the class is not really a Servlet because it doesn't have a reference to the ServletConfig, which provides all the initialisation parameters etc.


Why cant a container call constructor having parameters?

As it is the container that manages a servlets lifecycle, you must define a generic way of working for all servlets. You can't use the constructor because otherwise you would have to modify the container to tell him to instantiate this particular servlet.

0 Comments:

Post a Comment

<< Home