This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android 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: 12761
    
    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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Why dont we use constr instead of init method ?
 
Similar Threads
why we need init method in servlet
Call destroy() inside init()
Can we write constructor for Servlets?
Why Init() method
What am I doing wrong ?