wood burning stoves
The moose likes Servlets and the fly likes init missing in servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "init missing in servlet" Watch "init missing in servlet" New topic

init missing in servlet

Raj Jindal
Ranch Hand

Joined: Jan 17, 2003
Posts: 50
what will happen if a servlet dont have an init() method. Wil it serve requests or wat possible ??
Frank Carver

Joined: Jan 07, 1999
Posts: 6920
If your servlet extends HttpServlet or GenericServlet, then it automatically gets a basic "init" method provided by the parent class.
If you have nothing ro do in "init", you don't need to bother writing one.

Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Ivan Tamayo
Ranch Hand

Joined: Aug 13, 2001
Posts: 49
A servlet is not required to have a init() method.
bharat nagpal
Ranch Hand

Joined: Oct 26, 2002
Posts: 76
According to Servlet specifications, each servlet should provide life cycle methods, so that container should be able to call them at appropriate time. The basic life-cycle methods are provided in Servlet interface. The GenericServlet class implements Servlet interface and HttpServlet class extends GenericServlet. You can implement Servlet interface, but that's not a good practice, as you will have to provide the implementation of all the methods. So we either extend GenericServlet or HttpServlet Class, depending upon the requirement, and thats why we need not to worry about init() and destroy() methods in case we don't want to do anything in init().
[ February 02, 2004: Message edited by: bhart nagpal ]
I agree. Here's the link: http://aspose.com/file-tools
subject: init missing in servlet
It's not a secret anymore!