Meaningless Drivel is fun!
The moose likes Servlets and the fly likes load-on-startup Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "load-on-startup" Watch "load-on-startup" New topic


Sachin Deshpande

Joined: Jan 31, 2001
Posts: 25
I have a singleton servlet which i want to load on startup of tomcat server. I have added 'load-on-startup' tag with a random value(23) in web.xml file of the application which contains this servlet. I have some system.out.printlns in this servlet which print out something when the servlet has been loaded(and I can confirm that the servlet has been genuinely loaded. I cant see these System.out.println s! But when the servlet is explicitly called, i can see the system.out.printlns, suggesting that the servlet was not loaded when tomcat started. Am I missing something? How do I see those system.out.printlns at startup
nirmal baba

Joined: Apr 06, 2001
Posts: 10
Loading a servlet involves three things-class loading from deployment archive+instantiation+initialization!!....In ur case even though the servlet is getting instantiated and loaded at startup ,it is not showing the System.out.println statements probably because u have put them in the service()/doGet()/doPost() method of ur servlet!! That's why they r showing up when one of these methods is invoked as a part of request processing.
They will appear at startup time only if u keep them in the init() method...Kindly try and confirm
Good Luck
Sachin Deshpande

Joined: Jan 31, 2001
Posts: 25
yes the system.out.printlns were there in the service method
putting them in init worked
I agree. Here's the link:
subject: load-on-startup
It's not a secret anymore!