• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

The World of Servlet

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI!!! ppl...

What is meant by overriding an init() method of a servlet?Do we actually require it? If yes, when?
I wanted a clear idea on this!!!
[ April 24, 2006: Message edited by: Bear Bibeault ]
 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Gagan,

init() method is the way to put initialization code to your servlet. For example if you wanna open a DB connection or initialize any kind of code, init() is the place to do it.

On the other side, there is destroy() method that can UNDO everything you have done in init( close connections or similar ).

If you're a newcomer( I believe you are ), welcome to the servlet world.

I would recommend this free book for learning servlet. It is for the previous version of servlets, but it is a start. I would recommend to buy the second edition if you have the funds.

Happy Learning!
 
Ice Penov
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh, I forgot.

No, you don't have to override init() or destroy() if you don't have needs to do it.
 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
init() method is executed when the servlet is loaded for the first time in memory. So as Ice said activities like establishing database connections or initializing the values of certain variables (mostly static variables are initialized here)
You may or may not override this method.

Enjoy servlets. If you are working on Tomcat, you can refer to my tutorial also!
 
reply
    Bookmark Topic Watch Topic
  • New Topic