aspose file tools*
The moose likes Servlets and the fly likes Init and Constructor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Init and Constructor" Watch "Init and Constructor" New topic
Author

Init and Constructor

Padma NI
Greenhorn

Joined: Jun 18, 2003
Posts: 1
what is first invoked when a servlet is fist called? Init or constructor? and why do we need to register servlet with diferent names and have different instances?
srinivas madugula
Greenhorn

Joined: Apr 12, 2003
Posts: 6
hai,
init is not a static method. so it cannot be called with out creating an instance. to creat an instance you must use constructor.
i dont know why you asked this question.
bye
have a good one
ramu velagaturi
Greenhorn

Joined: Jun 20, 2003
Posts: 1
init method is first called
Panagiotis Varlagas
Ranch Hand

Joined: Nov 27, 2000
Posts: 233
init() is an instance method. This means that, in order for the servlet to invoke init() it needs to have an instance of your servlet.
aServlet.init();
In order to have a instance of your servlet, the servlet container needs to have executed an statement which might look like this:
aServlet = new YourServlet();
I.e. the constructor gets executed first.
Morale of the story: Brush up on your Java fundas!
[ June 20, 2003: Message edited by: Panagiotis Varlagas ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Init and Constructor
 
Similar Threads
init() method on servlets
can init() be replaced in servlet?
Why is init() needed?
init and constructor in servlet
Usage of Constructor ant Init() Method