[Logo]
Forums Register Login
init missing in servlet
what will happen if a servlet dont have an init() method. Wil it serve requests or wat possible ??
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.
A servlet is not required to have a init() method.
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 ]
No. No. No. No. Changed my mind. Wanna come down. To see this tiny ad:
Why should you try IntelliJ IDEA ?
https://coderanch.com/wiki/696337/IntelliJ-IDEA


This thread has been viewed 717 times.

All times above are in ranch (not your local) time.
The current ranch time is
Jul 17, 2018 03:49:20.