Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why dont we use constr instead of init method ?

 
Vikram Deshmukh
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13055
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic