• 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() method in servlet

 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi friends,
May know the reason why init()method is that much important,if we have the constructor.And can i write the destroy() inside init() method.

please clarify me on these two questions.

thanks and regards,
sandya.
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
like here?
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

can i write the destroy()


Why don't you go download the servlet API document and read about the intended use of all of the servlet methods instead of these piecemeal questions?
This is a good starting point.
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

If everybody promise that they will provide a constructor with a parameter �ServletConfig� while creating a servlet then they might remove this method (not sure though).



How can you get the 'ServletConfig� in the construstor.It is possible only after the servlet is instantiated.

You can use the construstor though.. if you do not want to access and the 'ServletConfig� and may be define and initialise just the instance variables.
 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As already discussed servletConfig is not available in the constructor so init would be the right place to initialize.You you want to initialize something which is not dependent of context of servlet config then you can do that as well in the constructor (its not a preferred way of doing thogh)

destroy() is a callback method called by the container .. you can explictly call that but in that case that is just like any other method in the class ..no use..destroy is called by the container when its about you destroy the servlet (for running some code for cleaning )..

its something like overriding the finalize (in Object class)method and calling that with the hope that this would garbage collect the object.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But What is basic Difference between Constrctor() & Init() mthod ?

Regards.
Anil Borude
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
constructor is called while creating a object (its actually not a method) and init is a method ..A callback method called by the container after the constructor is called and it has servletConfig's reference.
 
I'd appreciate it if you pronounced my name correctly. Pinhead, with a silent "H". Petite 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