亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? counter.java

?? Examples From Java Examples in a Nutshell, 2nd Edition 書中的源碼
?? JAVA
字號:
/* * Copyright (c) 2000 David Flanagan.  All rights reserved. * This code is from the book Java Examples in a Nutshell, 2nd Edition. * It is provided AS-IS, WITHOUT ANY WARRANTY either expressed or implied. * You may study, use, and modify it for any non-commercial purpose. * You may distribute it non-commercially as long as you retain this notice. * For a commercial use license, or to purchase the book (recommended), * visit http://www.davidflanagan.com/javaexamples2. */package com.davidflanagan.examples.servlet;import javax.servlet.*;import javax.servlet.http.*;import java.io.*;import java.util.*;/** * This servlet maintains an arbitrary set of counter variables and increments * and displays the value of one named counter each time it is invoked.  It * saves the state of the counters to a disk file, so the counts are not lost * when the server shuts down.  It is suitable for counting page hits, or any * other type of event.  It is not typically invoked directly, but is included * within other pages, using JSP, SSI, or a RequestDispatcher **/public class Counter extends HttpServlet {    HashMap counts;      // A hash table: maps counter names to counts    File countfile;      // The file that counts are saved in    long saveInterval;   // How often (in ms) to save our state while running?    long lastSaveTime;   // When did we last save our state?    // This method is called when the web server first instantiates this    // servlet.  It reads initialization parameters (which are configured    // at deployment time in the web.xml file), and loads the initial state    // of the counter variables from a file.    public void init() throws ServletException {	ServletConfig config = getServletConfig();	try {	    // Get the save file.	    countfile = new File(config.getInitParameter("countfile"));	    // How often should we save our state while running?	    saveInterval = 		Integer.parseInt(config.getInitParameter("saveInterval"));	    // The state couldn't have changed before now.	    lastSaveTime = System.currentTimeMillis();	    // Now read in the count data	    loadState();	}	catch(Exception e) {	    // If something goes wrong, wrap the exception and rethrow it	    throw new ServletException("Can't init Counter servlet: " +				       e.getMessage(), e);	}    }    // This method is called when the web server stops the servlet (which    // happens when the web server is shutting down, or when the servlet is    // not in active use.)  This method saves the counts to a file so they    // can be restored when the servlet is restarted.    public void destroy() {	try { saveState(); }  // Try to save the state	catch(Exception e) {} // Ignore any problems: we did the best we could    }    // These constants define the request parameter and attribute names that    // the servlet uses to find the name of the counter to increment.    public static final String PARAMETER_NAME = "counter";    public static final String ATTRIBUTE_NAME =	"com.davidflanagan.examples.servlet.Counter.counter";    /**     * This method is called when the servlet is invoked.  It looks for a     * request parameter named "counter", and uses its value as the name of     * the counter variable to increment.  If it doesn't find the request     * parameter, then it uses the URL of the request as the name of the     * counter.  This is useful when the servlet is mapped to a URL suffix.     * This method also checks how much time has elapsed since it last saved     * its state, and saves the state again if necessary.  This prevents it     * from losing too much data if the server crashes or shuts down without     * calling the destroy() method.     **/    public void doGet(HttpServletRequest request, HttpServletResponse response)        throws IOException    {	// Get the name of the counter as a request parameter	String counterName = request.getParameter(PARAMETER_NAME);		// If we didn't find it there, see if it was passed to us as a	// request attribute, which happens when the output of this servlet	// is included by another servlet	if (counterName == null)	    counterName = (String) request.getAttribute(ATTRIBUTE_NAME);	// If it wasn't a parameter or attribute, use the request URL.	if (counterName == null) counterName = request.getRequestURI();	Integer count;  // What is the current count?	// This block of code is synchronized because multiple requests may	// be running at the same time in different threads.  Synchronization	// prevents them from updating the counts hashtable at the same time	synchronized(counts) {	    // Get the counter value from the hashtable	    count = (Integer)counts.get(counterName);	    	    // Increment the counter, or if it is new, log and start it at 1	    if (count != null) count = new Integer(count.intValue() + 1);	    else {		// If this is a counter we haven't used before, send a message		// to the log file, just so we can track what we're counting		log("Starting new counter: " + counterName);		// Start counting at 1!		count = new Integer(1);	    }	    	    // Store the incremented (or new) counter value into the hashtable	    counts.put(counterName, count);	    // Check whether saveInterval milliseconds have elapsed since we	    // last saved our state.  If so, save it again.  This prevents	    // us from losing more than saveInterval ms of data, even if the	    // server crashes unexpectedly.  	    if (System.currentTimeMillis() - lastSaveTime > saveInterval) {		saveState();		lastSaveTime = System.currentTimeMillis();	    }	}  // End of synchronized block		// Finally, output the counter value.  Since this servlet is usually	// included within the output of other servlets, we don't bother	// setting the content type.	PrintWriter out = response.getWriter();	out.print(count);    }    // The doPost method just calls doGet, so that this servlet can be    // included in pages that are loaded with POST requests    public void doPost(HttpServletRequest request,HttpServletResponse response)        throws IOException    {	doGet(request, response);    }    // Save the state of the counters by serializing the hashtable to    // the file specified by the initialization parameter.    void saveState() throws IOException {	ObjectOutputStream out = new ObjectOutputStream(		    new BufferedOutputStream(new FileOutputStream(countfile)));	out.writeObject(counts);  // Save the hashtable to the stream	out.close();              // Always remember to close your files!    }    // Load the initial state of the counters by de-serializing a hashtable    // from the file specified by the initialization parameter.  If the file    // doesn't exist yet, then start with an empty hashtable.    void loadState() throws IOException {	if (!countfile.exists()) {	    counts = new HashMap(); 	    return;	}	ObjectInputStream in = null;	try {	    in = new ObjectInputStream(		   new BufferedInputStream(new FileInputStream(countfile)));	    counts = (HashMap) in.readObject();	}	catch(ClassNotFoundException e) {	    throw new IOException("Count file contains bad data: " +				  e.getMessage());	}	finally {	    try { in.close(); }	    catch (Exception e) {}	}    }}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产激情视频一区二区在线观看| 亚洲一区在线观看网站| 4438亚洲最大| 欧美一区国产二区| 日韩免费电影网站| 精品国产91乱码一区二区三区| 日韩一区二区在线观看视频| 欧美一区二区私人影院日本| 日韩午夜中文字幕| 国产午夜精品理论片a级大结局| 久久欧美中文字幕| 中文字幕一区二区5566日韩| 《视频一区视频二区| 一区二区三区在线影院| 亚洲va国产va欧美va观看| 欧美aⅴ一区二区三区视频| 精品综合久久久久久8888| 国产精品456露脸| 懂色av一区二区夜夜嗨| 91色视频在线| 欧美电影一区二区三区| www国产成人免费观看视频 深夜成人网| 精品毛片乱码1区2区3区| 国产精品免费看片| 亚洲第四色夜色| 激情成人综合网| 色综合久久久久| 91精品国产一区二区三区| 久久伊人蜜桃av一区二区| 亚洲色图制服丝袜| 蜜臀av性久久久久av蜜臀妖精| 国产成人综合视频| 欧美日韩国产大片| 日本一区免费视频| 香蕉av福利精品导航| 成人午夜电影网站| 日韩一区二区三区视频| 亚洲天堂2014| 精品一区二区影视| 在线观看网站黄不卡| 久久久久久久久久久久久夜| 一区二区在线看| 国产一区999| 91精品国产免费久久综合| 国产精品第五页| 精品一区二区国语对白| 欧洲一区在线观看| 国产精品丝袜久久久久久app| 秋霞电影一区二区| 欧美体内she精高潮| 国产精品午夜在线观看| 精品一区二区在线播放| 欧美夫妻性生活| 亚洲精品日日夜夜| zzijzzij亚洲日本少妇熟睡| 精品久久久久久无| 午夜国产精品一区| 欧美在线|欧美| 亚洲黄一区二区三区| 成人丝袜18视频在线观看| 久久综合九色综合久久久精品综合| 五月激情综合网| 欧美日韩激情在线| 91亚洲精品乱码久久久久久蜜桃| 91天堂素人约啪| 久久久久久电影| 麻豆国产精品官网| 91精品一区二区三区久久久久久 | 欧美特级限制片免费在线观看| 久久久久久久久99精品| 韩国三级中文字幕hd久久精品| 91精品久久久久久久99蜜桃| 亚洲一区二区三区四区在线 | 91在线免费视频观看| 26uuu久久天堂性欧美| 黄色成人免费在线| 久久久一区二区| 成人激情av网| 亚洲精品综合在线| 欧美日韩一区精品| 亚洲成人精品在线观看| 欧美人xxxx| 免费的国产精品| 欧美成人一区二区| 国产精品自拍av| 中文字幕中文在线不卡住| 一本一道波多野结衣一区二区| 中文字幕制服丝袜一区二区三区| 99久久精品国产精品久久| 玉米视频成人免费看| 欧美日韩精品福利| 国产在线播放一区三区四| 日本一区二区三区电影| 暴力调教一区二区三区| 亚洲精品中文在线| 3d成人动漫网站| 国产一区在线观看视频| 国产精品国产自产拍高清av| 欧美视频一区二区三区四区| 美女在线一区二区| 中文字幕不卡在线播放| 91免费国产在线| 日韩黄色一级片| 久久久久久久久久看片| 在线观看不卡视频| 国模冰冰炮一区二区| 国产精品成人一区二区艾草 | 精品一区二区三区欧美| 国产精品免费人成网站| 欧美精品视频www在线观看| 国精产品一区一区三区mba视频| 亚洲视频网在线直播| 欧美tickle裸体挠脚心vk| 成人小视频免费观看| 午夜久久久久久久久| 久久精品综合网| 欧美日韩国产欧美日美国产精品| 国产成人一级电影| 日韩av不卡在线观看| 亚洲欧美日韩国产综合| 精品久久久久一区二区国产| 欧美中文字幕不卡| av一区二区久久| 国产麻豆精品视频| 日韩不卡在线观看日韩不卡视频| 中文字幕一区二区三区不卡| 精品福利一二区| 337p亚洲精品色噜噜狠狠| 97se亚洲国产综合在线| 国产精品一区免费在线观看| 视频在线观看一区二区三区| 亚洲日韩欧美一区二区在线| 亚洲精品一区二区三区精华液 | 国产精品一区二区不卡| 亚洲线精品一区二区三区八戒| 中文字幕第一区| 久久久久国产精品免费免费搜索| 69久久夜色精品国产69蝌蚪网| 欧美亚州韩日在线看免费版国语版| 成人app网站| 岛国精品在线观看| 成人免费视频免费观看| 国产成人精品一区二区三区四区 | 国产一区二区三区av电影| 香蕉影视欧美成人| 一区二区三区电影在线播| 中文字幕成人av| 国产目拍亚洲精品99久久精品| 精品成人a区在线观看| 欧美日韩不卡一区| 91精品国产麻豆国产自产在线 | 欧美色视频在线| 色视频一区二区| 色综合久久66| 在线精品视频小说1| 在线一区二区观看| 欧美视频在线一区| 在线日韩国产精品| 欧美日韩视频在线第一区| 欧美日本韩国一区| 欧美一区永久视频免费观看| 精品久久久久久久人人人人传媒| 精品国产亚洲在线| 亚洲国产成人午夜在线一区| 国产精品久久久久久久第一福利| 亚洲精品久久嫩草网站秘色| 亚洲午夜成aⅴ人片| 婷婷综合在线观看| 国产在线精品一区二区夜色| 国产一区二区三区在线看麻豆| 国产精品一区二区黑丝| 99久久精品情趣| 欧美日韩成人在线一区| 久久日一线二线三线suv| 国产精品嫩草久久久久| 亚洲国产精品欧美一二99| 蜜臀久久99精品久久久久久9| 国产老肥熟一区二区三区| 91老司机福利 在线| 欧美一区二区三区人| 国产亚洲欧美激情| 亚洲高清一区二区三区| 久久99国产精品免费网站| 国产不卡在线一区| 欧美日韩综合在线| 久久女同互慰一区二区三区| 一二三四社区欧美黄| 国产一区二区三区免费| 色哦色哦哦色天天综合| 精品va天堂亚洲国产| 亚洲特黄一级片| 久久精品国产一区二区三区免费看| 国产91丝袜在线播放| 在线电影欧美成精品| 久久久久久黄色| 亚洲国产成人精品视频| 粉嫩av一区二区三区| 欧美电视剧免费全集观看| 依依成人综合视频| 成人国产一区二区三区精品|