要在应用程序启动或停止时执行操作,您应该使用ServletContextListener:http://download.oracle.com/javaee/6/api/javax/servlet/ServletContextListener.html
在web.xml中:
<web-app>
...
<listener>
<listener-class>com.example.Listener</listener-class>
</listener>
...
</web-app>
Run Code Online (Sandbox Code Playgroud)
与Peter Knego的提议相比,此解决方案可以移植到任何servlet容器,而不仅限于Tomcat.
| 归档时间: |
|
| 查看次数: |
3262 次 |
| 最近记录: |