On Fri, 12 Oct 2007, HODAC, Olivier wrote: > I am developping my first webapp, and I need to do things at the > server launching step. > > I understood that when a client sends the first request to the server, > it loads the required classes and instanciates them. So, I have to > wait for the first client to connect.
Yes, pretty much everything in Java is loaded on demand. > In my application, I have to perform stuff when the server starts. > Where do I have to put this code? There are two ways: In old systems (where the container implements Java Servlet specification version 2.2 or earlier) you declare a servlet to be initialized on startup. You then call your application initialization routines from the init() method of this servlet. To keep things organised, it might be best that the servlet you use for application initialization does not participate in handling user events. In recent systems (so, for Servler spec v2.3 and later), you write a ServletContextListener to call your startup code. If your application contains some objects that are designed to be available for the whole lifetime of the web application, you place those objects available in the ServletContext. For the details, please see the Java Servlet Specification (pick a version that matches what is implemented by your application server). -- Wolf a.k.a. Juha Laiho Espoo, Finland (GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++ "...cancel my subscription to the resurrection!" (Jim Morrison) --------------------------------------------------------------------- To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]