Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

init() method usage

 
Harikrishna Gorrepati
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I am trying to understand the difference between these init() methods as given in the comments.
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2277
81
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Harikrishna,

The javax.Servlet Interface consists of a method called init(ServletConfig sc), which is used to save the ServletConfig object in the Servlet so that you can access some init parameters and so on.

The GenericServlet implements the javax.Servlet which means that it has to implement the init(ServletConfig sc) method. As a convenience to the Servlet programmers (like us) they dicided to add a init() method.

When we write our own Servlet and we want to do some initialization we only have to override the init() method and all the default initialization (saving the ServletConfig object) is taken care of. GenericServlet.init(ServletConfig sc) is called by the servlet container and that method actually calls GenericServlet.init() method.

Regards,
Frits
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic