Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

servlet life cycle - init() method

 
Ram Gokul
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am confused by the 2 init() methods - one with servlet config and one without parameter. which is part of the life cycle methods.

HFS book / sun website says ..it will call init() and we can put some init code there . in Sun's web site , they also have some initialization example. Plus there is no super.init() in that method.

But searching on the net , for example , www.roseindia.net , they have quoted init(servletconfig) method as part of initialiation which has super.init(config).If i start a new servlet in ORacle Jdeveloper , a init(Servletconfig) method is automatically created with super.init(config) method . There is no init() method .

Can someone clarify which method is part of servlet life cycle and bit more on this process.

Thanks
 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

The init(ServletConfig) is the life-cycle method. This method is defined in the Servlet API. The another init() is a conveniance method which is definded in GeneriServlet Abstract class. It not part of life cycle. The init() method is called by the init(ServletCofig) method as per the Servlet documentation. If the vendor directly developing the Servlet class which does not extend the GenericServlet, but implement the API interface contarct, then it is not necessary to them to define the init() conveniance method as it is not part of contract. Also it is not necessary to implement the ServletConfig interface for the base class of the servlet as GenericServlet does.

Thanks
 
KasiMurugan Ramasamy
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Narendra,

Servlet Spec says that we need to extends HttpServlet, if we need to write a servlet. HttpSerlvet extends GenericServlet. Then only container can load the servlet.

I can't get you," Vendor implements the API but don't need extends GenericServlet", that means container not servlet container. It becomes vendor specific code, know?.

Could you clarify me?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic