1. 程式人生 > >ServletContextListener的用法和例項

ServletContextListener的用法和例項

1)ServletContextListener:
ServletContextListener能監聽到你的應用程式的啟動和銷燬。

例 2.2.1.1

package com;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
public class MyServletContextListener implements
ServletContextListener {
    public void contextDestroyed(ServletContextEvent arg0) {
        System.out.println("Destroyed 被執行");
    }
    public void contextInitialized(ServletContextEvent arg0) {
        ServletContext sc=arg0.getServletContext();
        System.out.println("馬克-to-win Initialized 被執行"+sc.getMajorVersion());
    詳情請見:

http://www.mark-to-win.com/index.html?content=Jsp/jspUrl.html&chapter=Jsp/jsp6_web.html#ServletContextListener