u can implement the ServletContextListener interface in a java class
to access 2 methods namely,
-
public void contextInitialized(ServletContextEvent e)
-
{
-
//your code here;
-
}
-
and
-
public void contextDestroyed(ServletContextEvent e)
-
{
-
//cleaning up;
-
}
-
from the parameter e you can access the context and write whatever code u wish to execute within the first of the two methods i mentioned.
and one more thing
add this code to your web.xml config file
<listener>
<listener-class>mypackage.myclass</listener-class>
</listener>