Hi, I have a question about init() and init(ServletConfig config) both used. I am confused about which one is used in initializing servlerts? Also, in servlet called InitDestroyCounter, there is a FileReader reader = new FileReader("InitDestroyCounter.initial"); in the init(). I don't understand what is "InitDestroyCounter.initial"? There is no initParameter specified in the Web.xml for the servlet initDestroyCounter. Thanks in advance.
Phil Hanna<BR>Sun Certified Programmer for the Java 2 Platform<BR>Author of :<BR><A HREF="http://www.amazon.com/exec/obidos/ASIN/0072127686/electricporkchop/107-3548162-1137317" TARGET=_blank rel="nofollow">JSP: The Complete Reference</A><BR><A HREF="http://www.amazon.com/exec/obidos/ASIN/0072124253/electricporkchop/107-3548162-1137317" TARGET=_blank rel="nofollow">Instant Java Servlets</A>
There are two versions of init: one that takes no arguments and one that takes a ServletConfig object as an argument. The first version is used when the servlet does not need to read any settings that vary from server to server. The second version of init is used when the servlet needs to read server-specific settings before it can complete the initialization. For example the servlet need to know about database settings, password files, etc, so the init method takes a ServletConfig as an argument. ServletConfig has a getInitParameter method with which you can look up initialization parameters associated with the servlet, just as with the getParameter method used in the init method of applets. This is from the Core Servlets and JavaServerPages from Marty Hall(a great book). I hope this help. Marcos Maia.
Hi Cameron, The overloaded no-argument init() method was added , so that if a developer carelessly overrides the method, he would still be able to use getServletConfig() top retreive the ServletConfig object.I think, this was added in JSDK Version 2.1 With the addition of this method, the GenericServlet class has init(ServletConfig) method calling init() at the end.The init() is empty in GenericServlet class. So with this, you can safely include the initialization code in init() without having to worry about calling super.init(config) Hope this helps. Regards, Sandeep Desai email@example.com
Sun Certified Java ProgrammerScored 93 per cent
Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java Scored 56 out of 59
IBM Enterprise Connectivity with J2EE Scored 72 per cent
Enterprise Development on the Oracle Internet Platform Scored 44 out of 56
[This message has been edited by Desai Sandeep (edited April 27, 2001).]
<b>Sandeep</b> <br /> <br /><b>Sun Certified Programmer for Java 2 Platform</b><br /> <br /><b>Oracle Certified Solution Developer - JDeveloper</b><br /><b>-- Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java </b><br /><b>-- Object-Oriented Analysis and Design with UML</b><br /> <br /><b>Oracle Certified Enterprise Developer - Oracle Internet Platform</b><br /><b>-- Enterprise Connectivity with J2EE </b><br /><b>-- Enterprise Development on the Oracle Internet Platform </b>