• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            牽著老婆滿街逛

            嚴(yán)以律己,寬以待人. 三思而后行.
            GMail/GTalk: yanglinbo#google.com;
            MSN/Email: tx7do#yahoo.com.cn;
            QQ: 3 0 3 3 9 6 9 2 0 .

            jsp中監(jiān)聽器和定時(shí)器的結(jié)合的程序

            轉(zhuǎn)載自:http://chengyue2007.iteye.com/blog/472431

            package Unit.Test;

            import javax.servlet.ServletContext;
            import javax.servlet.ServletContextAttributeEvent;
            import javax.servlet.ServletContextAttributeListener;
            import javax.servlet.ServletContextEvent;
            import javax.servlet.ServletContextListener;

            import test.TimerTest;

            public class ServletConextListener implements ServletContextListener,
                    ServletContextAttributeListener 
            {

                
            private ServletContext servletContext;

                
            private String AttributeName;

                
            private Object AttributeValue;

                
            public void contextDestroyed(ServletContextEvent sce) {
                    System.out.println(
            "####ServletContext上下文銷毀");

                }


                
            public void contextInitialized(ServletContextEvent sce) {
                    servletContext 
            = sce.getServletContext();
                    
                    TimerTest test
            =new TimerTest();
                    
            //這個(gè)是定時(shí)器的內(nèi)容
                    
                    System.out.println(
            "####上下文初始化");
                    
                    System.out.println(
            "####ServletContext當(dāng)前初始目錄為:"
                            
            + this.servletContext.getRealPath("/"));
                    
                }


                
            public void attributeAdded(ServletContextAttributeEvent sce) {
                    AttributeName 
            = sce.getName();
                    AttributeValue 
            = sce.getValue();
                    System.out.println(
            "####ServletContext增加一個(gè)屬性:");
                    System.out.println(
            "AttributeName:" + AttributeName);
                    System.out.println(
            "AttributeValue:" + AttributeValue);

                }


                
            public void attributeRemoved(ServletContextAttributeEvent sce) {
                    AttributeName 
            = sce.getName();
                    AttributeValue 
            = sce.getValue();
                    System.out.println(
            "####ServletContext刪除一個(gè)屬性:");
                    System.out.println(
            "AttributeName:" + AttributeName);
                    System.out.println(
            "AttributeValue:" + AttributeValue);
                }


                
            public void attributeReplaced(ServletContextAttributeEvent sce) {
                    AttributeName 
            = sce.getName();
                    AttributeValue 
            = sce.getValue();
                    System.out.println(
            "####ServletContext替換一個(gè)屬性:");
                    System.out.println(
            "AttributeName:" + AttributeName);
                    System.out.println(
            "AttributeValue:" + AttributeValue);
                }


            }

            上面是監(jiān)聽器的內(nèi)容,下面是定時(shí)器的內(nèi)容

            package test;

            import java.io.IOException;
            import java.util.Date;
            import java.util.Timer;

            public class TimerTest {
            public TimerTest(){
            Date time
            =new Date();
            time.setHours(
            17);
            time.setMinutes(
            48);
            time.setSeconds(
            20);
            Timer timer
            = new Timer();
            timer.schedule(
            new MyTask(),time);//在1秒后執(zhí)行此任務(wù),每次間隔2秒
            }


            static class MyTask extends java.util.TimerTask{
            @Override
            public void run() {

            System.out.println(
            "我是來測試的。。我兩秒出來一次");
            }

            }

            }



            下面是xml的配置方法
            <listener>
            <listener-class>Unit.Test.ServletConextListener</listener-class>
            </listener>

            posted on 2012-05-04 12:56 楊粼波 閱讀(777) 評(píng)論(0)  編輯 收藏 引用


            只有注冊用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            亚洲国产美女精品久久久久∴| 久久不见久久见免费视频7| 国内精品伊人久久久久| 久久九九全国免费| 中文字幕亚洲综合久久菠萝蜜 | 久久伊人精品一区二区三区| 精品国产乱码久久久久软件| 伊人久久精品线影院| 久久精品国产男包| 国产精品久久久久久福利漫画 | 欧美久久久久久午夜精品| 久久精品18| 亚洲狠狠综合久久| 精品无码久久久久国产动漫3d| 麻豆亚洲AV永久无码精品久久| 久久婷婷五月综合色奶水99啪| 久久精品国产网红主播| 一本综合久久国产二区| 99久久久久| 国产亚洲欧美精品久久久| 国产亚洲综合久久系列| 亚洲国产精品无码久久青草 | 无码人妻久久一区二区三区| 国产精品一区二区久久精品无码| 久久99精品综合国产首页| 亚洲七七久久精品中文国产| 91精品国产高清久久久久久国产嫩草| 久久天天婷婷五月俺也去| 久久亚洲电影| 国产99久久久久久免费看| 精品久久久久久中文字幕人妻最新| 久久午夜夜伦鲁鲁片免费无码影视 | 精品伊人久久大线蕉色首页| 久久免费观看视频| 亚洲国产综合久久天堂 | 一本久道久久综合狠狠爱| 伊人久久大香线焦AV综合影院 | 国产精品欧美亚洲韩国日本久久 | av无码久久久久不卡免费网站 | 狠狠干狠狠久久| 久久久91精品国产一区二区三区|