• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

init method in servlets

 
sitaram irrinki
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the special feature of init() in servlets
 
Ryan McGuire
Ranch Hand
Posts: 1081
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
init(ServletConfig) gets called when the servlet class is loaded. This may be the first time a client a calls it or when the application server is started, depending on <load-on-startup> tag in your web.xml file.

The default implmentation of init(ServletConfig) does some stuff and then calls init(). If I understand correctly, the init() in the HttpServlet base class doesn't actually do anything. It's sole purpose is to be overridden in subclasses so that init(ServletConfig) can call it.

If you have initialization to be done for your servlet, such as reading in configuration files, instantiating data structures, opening database connections, etc., override init().

Ryan

[edit: added some italics]
[ May 17, 2005: Message edited by: Ryan McGuire ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic