• <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>

            牽著老婆滿街逛

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

            jsp中監聽器和定時器的結合的程序

            轉載自: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();
                    
            //這個是定時器的內容
                    
                    System.out.println(
            "####上下文初始化");
                    
                    System.out.println(
            "####ServletContext當前初始目錄為:"
                            
            + this.servletContext.getRealPath("/"));
                    
                }


                
            public void attributeAdded(ServletContextAttributeEvent sce) {
                    AttributeName 
            = sce.getName();
                    AttributeValue 
            = sce.getValue();
                    System.out.println(
            "####ServletContext增加一個屬性:");
                    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刪除一個屬性:");
                    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替換一個屬性:");
                    System.out.println(
            "AttributeName:" + AttributeName);
                    System.out.println(
            "AttributeValue:" + AttributeValue);
                }


            }

            上面是監聽器的內容,下面是定時器的內容

            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秒后執行此任務,每次間隔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 楊粼波 閱讀(775) 評論(0)  編輯 收藏 引用

            99精品久久精品一区二区| 国产成人精品综合久久久久| 久久精品久久久久观看99水蜜桃| 99久久99久久| 成人久久精品一区二区三区| 亚洲va久久久噜噜噜久久| 97视频久久久| 伊人久久大香线蕉综合Av| 无码人妻久久一区二区三区蜜桃| 久久一本综合| 久久精品国产亚洲αv忘忧草| 久久五月精品中文字幕| 日本精品久久久久久久久免费| 国产精品亚洲综合专区片高清久久久| 狠狠色丁香婷婷综合久久来| 99热精品久久只有精品| 一本伊大人香蕉久久网手机| 久久国产精品免费一区| 四虎久久影院| 久久99亚洲网美利坚合众国| 精品亚洲综合久久中文字幕| 91精品日韩人妻无码久久不卡| 狠狠人妻久久久久久综合蜜桃| 蜜臀久久99精品久久久久久| 综合久久一区二区三区| 午夜欧美精品久久久久久久| 999久久久无码国产精品| 久久久久18| 亚洲AV无码久久| 热久久国产精品| 中文字幕久久精品无码| 国产99久久精品一区二区| 久久精品亚洲福利| 久久香综合精品久久伊人| 精品久久人人爽天天玩人人妻| 亚洲乱码日产精品a级毛片久久 | 亚洲精品美女久久久久99| 亚洲国产精品人久久| 久久人人爽人人爽人人片av麻烦| 国产欧美久久久精品| 久久只有这里有精品4|