आपको ServletContextListner इंटरफ़ेस को कार्यान्वित करने और उस कोड को लिखने की आवश्यकता है जिसे आप टॉमकैट स्टार्ट अप पर निष्पादित करना चाहते हैं।
यहां इसके बारे में एक संक्षिप्त विवरण दिया गया है।
ServletContextListner javax.servlet पैकेज के अंदर है।
यहां एक संक्षिप्त कोड है कि इसे कैसे करें।
public class MyServletContextListener implements ServletContextListener {
@Override
public void contextDestroyed(ServletContextEvent arg0) {
//Notification that the servlet context is about to be shut down.
}
@Override
public void contextInitialized(ServletContextEvent arg0) {
// do all the tasks that you need to perform just after the server starts
//Notification that the web application initialization process is starting
}
}
और आप अपने तैनाती वर्णनकर्ता web.xml में कॉन्फ़िगर की जरूरत
<listener>
<listener-class>
mypackage.MyServletContextListener
</listener-class>
</listener>
आप देख रहे हैं कुछ "ServletContextListener" कहा जाता है के लिए, यह तरीकों की जरूरत है। –
https://stackoverflow.com/questions/3468150/using-special-auto-start-servlet-to-initialize-on-startup-and-share-plication – rogerdpack