Why do we need a constructor for a Servlet class when we can use init method? I know constructors are called before the init method, but not able to figure out how initialising the variables in constructors help than doing the same in init method. Any info on this will be of great help.
Thanks and Regards
Arun
-
Constructors in a Servlet. (4 messages)
- Posted by: Arun Kumar
- Posted on: August 29 2005 04:31 EDT
Threaded Messages (4)
- Constructors in a Servlet. by JT Wenting on August 29 2005 08:37 EDT
- Constructors in a Servlet. by suresh nallamilli on August 29 2005 08:49 EDT
- Constructors in a Servlet. by Mani Venkatesan on August 29 2005 19:15 EDT
- Constructors in a Servlet. by NOEL BRANZUELA on August 30 2005 01:03 EDT
-
Constructors in a Servlet.[ Go to top ]
- Posted by: JT Wenting
- Posted on: August 29 2005 08:37 EDT
- in response to Arun Kumar
Normally you would never write a constructor for a servlet.
But as a servlet is a class like any other it will have one. -
Constructors in a Servlet.[ Go to top ]
- Posted by: suresh nallamilli
- Posted on: August 29 2005 08:49 EDT
- in response to Arun Kumar
when u r in a servlet class constructor it is just like writing a constructor in a normal java .
During the init mothod of the servlet you servlet object can use the services on the container -
Constructors in a Servlet.[ Go to top ]
- Posted by: Mani Venkatesan
- Posted on: August 29 2005 19:15 EDT
- in response to Arun Kumar
I was feeling unusually verbose. So I blogged on this...
http://23c.blogspot.com/2005/08/techie-sideslip.html -
Constructors in a Servlet.[ Go to top ]
- Posted by: NOEL BRANZUELA
- Posted on: August 30 2005 01:03 EDT
- in response to Arun Kumar
First, it is not advisable to create a constructor in a Servlet other than the default.
Second, the servlet container is managing the life-cycle of these servlet instances. Variables initialized inside the default constructor of a servlet will only be run once during servlet instantiation. Since servlet instance are actually reused, the constructor is not invoked anymore during reuse, but the init method is always called once the servlet is reused from the pool.