This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes init method in servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "init method in servlets" Watch "init method in servlets" New topic
Author

init method in servlets

sitaram irrinki
Ranch Hand

Joined: Feb 16, 2005
Posts: 158
what is the special feature of init() in servlets
Ryan McGuire
Ranch Hand

Joined: Feb 18, 2005
Posts: 1006
    
    3
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 ]
 
Consider Paul's rocket mass heater.
 
subject: init method in servlets
 
Similar Threads
Sturts Action servlet init params in web.xml file
when init() is being called?
servlet context
init methods of Servlets: need clarification
Servlet Initialization Doubt ...