posted 19 years ago
Hi Edmund,
I posted same question a few days ago, not sure how to provide reference of tht, here are two replies i got
---------------------------------------------
Servlet's init method is invoked after container instantiates servlet.
Servlet object made in container after constructor call, and this object requires to container to fill information like ServletConfig(i.e. init parameter info, servlet env. info, and so on..) .
if u move code from init to constructor , specialy init parameter accesing code, it will not work becaus uptill then no servletconfig set by container..
---------------------------------------------------
A servlet MUST be intiailized by container before it can service requests. There are many things done by container behind the scene when it initializes a servlet but for now you can understand this one easily:
Before invoking your overridden init method container will read servlet inti parameter from deployment descriptor and store them on in a special object called ServletConfig object.
There are three ways of getting this done by container:
1. Do not override init() at all. In this case container will call hidden version of init method init(ServletConfig config) this comes from Servlet interface implementation class.
2. Override this method and call super.init() method as a very first line inside method.
3. Override init() method of Generic servlet. This method is called by init(config)
Amar Verma<br />---------------<br />SCJP 1.4<br />SCWCD1.4 (Preparing)<br />Dont even follow the leading path, create your own path and leave the trail.