We have a Java app that runs on Websphere. I have one class that I want to load and initialize as soon as Websphere loads, or as soon as the app is reloaded within Websphere, without waiting for the first web page to be loaded. I'm pretty sure loading it in our subclass of HttpServlet is probably the wrong place. So what is the right place?
+3
A:
I think you want a ServletContextListener.
Before that was available, people would actually put this kind of code into a Servlet (not necessarily mapped to any url), and have that loaded on initialization. But ServletContextListener is the proper way now.
Goes into web.xml like this:
<web-app>
<listener>
<listener-class>
mypackage.MyContextListener
</listener-class>
</listener>
<servlet/>
<servlet-mapping/>
</web-app>
Thilo
2010-09-08 01:16:56
+1
A:
Hi,
As Thilo mentioned ServletContextListeners are good for Web Applications.
If your application does not use the Web Components then you could possibly be looking at WebSphere specific extensions too - StartUp Beans.
HTH Manglu
Manglu
2010-09-14 02:08:46
Thank you for that extra information. It's not what I need, but it's good to have it here in case somebody finds my question in a search.
Paul Tomblin
2010-09-14 11:02:21