File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Soft Skills this week in the Jobs Discussion 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: 12835
    
    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 ?