建立一个类,
实现ServletContextListener接口
在web.xml里加上监听
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
public class socketMain implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent sce) {
new MyThread().start();
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
}
class MyThread extends Thread
{
public void run()
{
System.out.println("测试开始");
}
}
}
web.xml加上
<listener>
<listener-class>com.calanger.app.admin.websocket.socketMain</listener-class>
</listener>