• <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 楊粼波 閱讀(778) 評論(0)  編輯 收藏 引用


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


            狠狠色婷婷综合天天久久丁香| 久久国产成人亚洲精品影院| 久久这里只有精品首页| 久久99九九国产免费看小说| 一本色道久久综合亚洲精品| 99久久99久久精品免费看蜜桃 | 久久99热这里只有精品66| 久久Av无码精品人妻系列| 久久99精品久久久久久噜噜| 亚洲色大成网站www久久九| 久久久久女教师免费一区| 午夜精品久久久久久久久| 久久精品成人免费国产片小草 | 国产精品无码久久四虎| 成人久久免费网站| 欧美精品丝袜久久久中文字幕| 久久久久人妻一区精品性色av| 性高朝久久久久久久久久| 人人狠狠综合久久亚洲88| 久久久久久久人妻无码中文字幕爆| 久久亚洲电影| 久久精品国产黑森林| 99久久国产免费福利| 99国产精品久久久久久久成人热| 一本一道久久a久久精品综合| 国产精品欧美久久久久天天影视| 97久久天天综合色天天综合色hd| 婷婷五月深深久久精品| 精品久久久久成人码免费动漫| 久久亚洲高清综合| 久久综合给合综合久久| 久久久久18| 女同久久| 亚洲国产成人精品女人久久久 | 久久综合亚洲鲁鲁五月天| 2020国产成人久久精品| 99久久这里只精品国产免费| 久久久久亚洲AV成人网人人网站 | 99精品国产综合久久久久五月天| 久久毛片一区二区| 日韩精品无码久久久久久|