• Post Reply Bookmark Topic Watch Topic
  • New Topic

The World of Servlet  RSS feed

 
Gagan Sabharwal
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • 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 ]
 
Ice Penov
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Abhishek Asthana
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • 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!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!