hi all, i am trying to write my first servlet. i have read that the init() methid is called just once. is that once for every new session. i am connecting to the DB in the init() and want different users to connect with different Connections. so am i right in saying that each time the user visits my page, the servlet will call it's init() method? thanks in advance.
Please correct me if I am wrong, but I think that inin() method is called only once and that is first time the servlet is loaded (invoked). I believe the service() method is the one that is invoked countless times. Anyway You need to just once create Your db connection so putting it in init() makes sense. So to summarize, I think that unless servlets method destroy() has been called, init() is called only once. Vladan [This message has been edited by Vladan Radovanovic (edited October 18, 2000).]
The init method is run when your servlet is first instantiated, NOT for each time a browser runs the servlet. In other words, every time a browser runs your servlet a thread is launched. The thread runs your doGet or doPost (or whatever). The init method is run once, when the servlet object is first created. Depending on the HTTP server your using the servlet may go away and have to be re-instantiated. In this case init is run again.