permaculture playing cards*
The moose likes Servlets and the fly likes Why dont we use constr instead of init method ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Why dont we use constr instead of init method ?" Watch "Why dont we use constr instead of init method ?" New topic
Author

Why dont we use constr instead of init method ?

Vikram Deshmukh
Greenhorn

Joined: Apr 22, 2000
Posts: 29
What is the benefit of having init(ServletConfig) ? As I know it does an initialization activity.
But if i provide constructor for a servlet, still, this method gets called prior to init()
then call gets redirected to either doGet or doPost.
In this case what is the extra mileage we get after having this init method ?
with regards,
vikram
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12675
    
    5
The servlet API requires an init method so that the servlet configuration can be passed properly. I suspect that one reason they did it this way is so the Servlet interface can neatly define all of the methods needed.
Use of the constructor is under the control of the servlet engine. Don't confuse the operation of the constructor and init with the flow of control during a request.
Bill


Java Resources at www.wbrogden.com
 
 
subject: Why dont we use constr instead of init method ?
 
Similar Threads
What am I doing wrong ?
why we need init method in servlet
Why Init() method
Call destroy() inside init()
Can we write constructor for Servlets?