aspose file tools*
The moose likes Beginning Java and the fly likes Can we use constructors instead of init() in servlets? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Can we use constructors instead of init() in servlets?" Watch "Can we use constructors instead of init() in servlets?" New topic
Author

Can we use constructors instead of init() in servlets?

Anto Telvin
Ranch Hand

Joined: Aug 12, 2008
Posts: 113
Hi all
I have one doubt abt servlet ..It is possible to use constuctors instead of init() in servelt .if we can use then how the web container will call that constuctor.

thanks


Anto Telvin Mathew<br />Many of the life failures are people who did not realize how close they were to success when they give up. EDISON
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

The constructor is called the first time a Servlet is used in a Web container. So you can do work in there. After the Servlet is created, the init method is called to do one time setup work. The purpose of the init method is to allow for setup work that needs to wait until the Servlet has been constructed.

Take a look at Servlet Life Cycle and Initializing a Servlet in the Java EE Tutorial for more information.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can we use constructors instead of init() in servlets?