I want to know the exact diffrence b/w listener nad <load on start up tag>
listener will be the first when we start the application and should execute first
<load on start up > tag do the same thing it load the servlet at the time of deployment
In HFSJ one example is given on page 171 . can i do the same thing with the <load on start up > tag ?
Cleared SCJP 1.5 | Cleared SCWCD 5.0
(SCEA/OCMJEA) in progress.....
First of all, the correct spelling is "load-on-startup". If you don't remember how tags are spelt, you might get surprises at the exam.
About your problem, listeners are loaded at deployment time, so they don't need a load-on-startup. Servlets, unlike listeners, are not loaded at deployment time, but the first time they are accessed. If you want to force a servlet to be initialized at deployment time, you can set "load-on-startup" for the servlet.
When the application is deployed, servlets are not loaded, not initialized. Imagine that you have some initialization stuff in a servlet's init() method, and that you want it to be initialized at startup, then you will need to tell the container to load your servlet immediately. You can use the "load-on-startup" tag to do so.
Try to make a servlet and to do something in the init method. Check what happens at startup, with and without "load-on-startup" set.
Christophe is rite,
Servlets executes on concept of Lazy Loading, it means they will load in memory when they called otherwise not, if some one like you wana call servlet (eager loaded) while on application start up, then you have to specify it in <load-on-startup>. listeners are eager loaded with application.