你需要实现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
}
}
Run Code Online (Sandbox Code Playgroud)
并在部署描述符web.xml中配置它
<listener>
<listener-class>
mypackage.MyServletContextListener
</listener-class>
</listener>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1157 次 |
| 最近记录: |