1. The servlet container needs a no-args constructor to create an instance from the class named in web.xml - therefore constructors with arguments are never used in a real servlet container - if you want to make one for testing outside a servlet container, feel free. 2. A servlet instance needs to know the ServletConfig information before it can work in a servlet container therefore there must be an init(ServletConfig conf) method.
Joined: Jul 28, 2006
ok, but we are having the init() method without arguments what about that
kumar kotha, JavaRanch is a community of people from all over the world, many of who are not native English speakers. While using abbreviations like "u" instead of spelling out "you" is convenient when text messaging your friends on a cell phone or in a chat room, it presents an extra challenge to those that are already struggling with English. Additionally, such shortcuts may confound automated translation tools that patrons of the Ranch may be making use of.
I would like to ask for your help in making the content of JavaRanch a little easier to read for everybody that visits here by not using such abbreviations.
Author and all-around good cowpoke
Joined: Mar 22, 2000
Look at the Servlet interface in the JavaDocs - you will see that only one init method is required in a servlet, the one using ServletConfig. The servlet container ALWAYS calls this method after creating an instance and before any requests are processed.
NOW - look at the GenericServlet abstract class JavaDocs - you will see that this class has added the init() as "a convenience method" along with many other methods. The init( config ) method in GenericServlet calls the init() method - as described in the JavaDocs.
Anybody serious about servlet programming should become familiar with the JavaDocs for the servlet related packages and the formal specification of the API.