• 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

init() or init(ServletConfig sc)?

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you overide both the init() and init(ServletConfig sf) methods, which one is called when the serlvet is instantiated?
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
first: init(ServletConfig sc)
then : init()

if init(ServletConfig sc) method fails then init() would not be executed.

As given in the docs:

init(ServletConfig sc) method is called by the servlet container to indicate to a servlet that the servlet is being placed into service
[ September 15, 2004: Message edited by: adeel ansari ]
 
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The container will always call init(ServletConfig) before placing a servlet in service. init() is a convenience method provided in GenericServlet.

The init(ServletConfig) of GenericServlet stores the ServletConfig object it receives from the servlet container for later use. It then makes a call to init().

If you override both,
- container still calls the life cycle method init(ServletConfig)
- you are responsible for calling super.init(config)
- init() will not be called, unless your implementation of init(ServletConfig) calls it.

Sheldon
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanx for pointing out sheldon. i just put it in reverse order. and paste the statement in the doc below. i am editing it.

Moreover, documentation says:

init() is a convenience method which can be overridden so that there's no need to call super.init(config).

Instead of overriding init(ServletConfig), simply override this method and it will be called by GenericServlet.init(ServletConfig config). The ServletConfig object can still be retrieved via getServletConfig()
[ September 15, 2004: Message edited by: adeel ansari ]
 
And tomorrow is the circus! We can go to the circus! I love the circus! We can take this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic