Two Laptop Bag*
The moose likes Servlets and the fly likes Servlet init method 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 "Servlet init method" Watch "Servlet init method" New topic
Author

Servlet init method

Milind Deodhar
Ranch Hand

Joined: Dec 06, 2000
Posts: 32
Question on servlet init method
O'Reilly book says that init method should pass along an object that implements ServletConfig interface.
Not inis is typically like this
public init (ServletConfig config),
Now servlet makes a call to init method, so which object does the servlet use to call init method.
I may be little confused here, but can enyone explain.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12756
    
    5
The important point is, you (servlet) never call the init method.
The servlet engine (container) calls the init method right after it creates the servlet object. The API guarantees that the init method will be finished before the first request is sent to the servlet. Your init method should grab all of the init parameters and handle any other initialization.
The destroy() method is similar, you never call it. The servlet engine calls destroy when it is about to remove a servlet object. This is where you have a final chance to clean up.
Bill

------------------
author of:
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Servlet init method
 
Similar Threads
Doubt in init method
init() method doubt?
init() or init(ServletConfig sc)?
passing ServletContext
init() method