This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one 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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript 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: 12769
    
    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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why dont we use constr instead of init method ?