• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

servlet life cycle - init() method

 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
reply
    Bookmark Topic Watch Topic
  • New Topic