I didnt developped in struts much, we had a contractor who built our presentation layer using struts, I myself coded the business logic. The thing is, I would like to know how to execute a certain function when struts loads that basicly initializes certain things (loggers, database, etc). I have it as a static initializer in one of my classes but it executes only when struts makes a call to one of our business logic parts. Instead I would like this to be executed right when struts (or even Tomcat maybe I dont know if its possible) starts. How can I do that (without having to call the contractor, who's on vacation ). Thanks!
Thanks Jason! It works when I try with a bogus example, but I get a weird problem when trying to run the initialization routine I want : tomcat doesnt start (it seems like it gets stuck in some kind of infinite loop, as my cpu jumps to 100% and I never get the message that tomcat is listening to ... I've done some trial and error and it seems like the part where I setup my loggers makes it do that (I'm using java.util.logging). If I comment out that part, tomcat starts fine. So anyways, maybe tomcat relies on it's own logging to believe it's started Up to this point I'm guessing tomcat uses the same logging facility and it doesnt like me screwing up with loggers before it's started (log messages dont appear when I init my logging before tomcat is started). Do you know any other way I can perform the same thing?
Simple solution Make a class and put this in your web.xml <servlet> <servlet-name>myservlet</servlet-name> <servlet-class>mypackage.MyClass</servlet-class> <init-param> <param-name>myds</param-name> <param-value>jdbc/MyDS</param-value> </init-param> <load-on-startup>10</load-on-startup> </servlet> Note the load-on-startup tag which tells the server, the priority loading order of this servlet. In the init of this class, you can load your objects and store them in some context avl to all applications (appcontext). I have this set up on both wl8 and tomcat4.1 Sahil