成人久久久久爱,国产精品乱码一区二三区小蝌蚪,毛片网站在线http://www.aygfsteel.com/yundixiaoduo/zh-cnFri, 08 Aug 2025 01:44:05 GMTFri, 08 Aug 2025 01:44:05 GMT60用 img 標簽 實現 網頁計數器http://www.aygfsteel.com/yundixiaoduo/archive/2010/12/02/339612.html云帝xiao墮云帝xiao墮Thu, 02 Dec 2010 07:21:00 GMThttp://www.aygfsteel.com/yundixiaoduo/archive/2010/12/02/339612.htmlhttp://www.aygfsteel.com/yundixiaoduo/comments/339612.htmlhttp://www.aygfsteel.com/yundixiaoduo/archive/2010/12/02/339612.html#Feedback0http://www.aygfsteel.com/yundixiaoduo/comments/commentRss/339612.htmlhttp://www.aygfsteel.com/yundixiaoduo/services/trackbacks/339612.html以下是CountServlet.java:
 1 import java.awt.Color;
 2 import java.awt.Font;
 3 import java.awt.Graphics;
 4 import java.awt.image.BufferedImage;
 5 import java.io.ByteArrayOutputStream;
 6 import java.io.FileInputStream;
 7 import java.io.FileOutputStream;
 8 import java.io.IOException;
 9 import java.util.Properties;
10 
11 import javax.imageio.ImageIO;
12 import javax.servlet.ServletException;
13 import javax.servlet.ServletOutputStream;
14 import javax.servlet.http.HttpServlet;
15 import javax.servlet.http.HttpServletRequest;
16 import javax.servlet.http.HttpServletResponse;
17 
18 public class CountServlet extends HttpServlet {
19 
20     private static final long serialVersionUID = 1L;
21 
22     public void doGet(HttpServletRequest request, HttpServletResponse response)
23             throws ServletException, IOException {
24         response.setContentType("image/jpeg");
25         // 設置瀏覽器不要緩存此圖片
26         response.setHeader("Pragma""No-cache");
27         response.setHeader("Cache-Control""no-cache");
28         response.setDateHeader("Expires"0);
29 
30         ServletOutputStream sos = response.getOutputStream();
31 
32         BufferedImage image = new BufferedImage(8020,
33                 BufferedImage.TYPE_INT_RGB);
34         Graphics g = image.getGraphics();
35 
36         g.setColor(Color.WHITE);
37         g.setFont(new Font(null, Font.ITALIC | Font.BOLD, 18));
38         String value = getAccessCount(request);
39         int len = value.length();
40         // 最大訪問次數不超過9999999
41         if (len > 7) {
42             value = "9999999";
43         } else {
44             String tmp = "";
45             for (int i = 0; i < 7 - len; i++) {
46                 tmp = tmp + "0";
47             }
48             value = tmp + value;
49         }
50         g.drawString(value, 018);
51         // 結束圖像的繪制過程,完成圖像
52         g.dispose();
53         // 避免因圖像大小超過Servlet引擎輸出緩沖區的大小而自動使用chunked編碼
54         ByteArrayOutputStream bos = new ByteArrayOutputStream();
55         ImageIO.write(image, "JPEG", bos);
56         byte[] buf = bos.toByteArray();
57         response.setContentLength(buf.length);
58         bos.close();
59         sos.write(buf);
60         sos.close();
61     }
62 
63     private String getAccessCount(HttpServletRequest request) {
64         // 得到引用頁面的URL地址,并以此作為訪問次數的檢索關鍵字
65         String pageKey = request.getHeader("referer");
66         if (pageKey == null) {
67             return "0";
68         }
69 
70         Properties settings = new Properties();
71         String countFilePath = getServletContext().getRealPath("/count.txt");
72         try {
73             FileInputStream fi = new FileInputStream(countFilePath);
74             settings.load(fi);
75             fi.close();
76         } catch (Exception e) {
77             e.printStackTrace();
78         }
79         String count = "0";
80         try {
81             count = settings.getProperty(pageKey);
82             if (count == null) {
83                 count = "0";
84             }
85             int c = Integer.parseInt(count) + 1;
86             count = new Integer(c).toString();
87             settings.put(pageKey, count);
88             FileOutputStream fi = new FileOutputStream(countFilePath);
89             settings.store(fi, "the page is accessed:");
90             fi.close();
91         } catch (Exception e) {
92             e.printStackTrace();
93         }
94         return count;
95     }
96 }
以下是Count.html:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
    本網頁已被訪問了
<img src="/servlet/CountServlet">
</body>
</html>



云帝xiao墮 2010-12-02 15:21 發表評論
]]>
主站蜘蛛池模板: 临桂县| 南雄市| 子洲县| 南平市| 平顶山市| 桑植县| 贵港市| 新郑市| 新和县| 合江县| 本溪| 怀化市| 藁城市| 吉安县| 夏邑县| 措美县| 洛南县| 青铜峡市| 阜城县| 屯留县| 张家港市| 虞城县| 平阳县| 普兰店市| 鹰潭市| 高邑县| 乌鲁木齐县| 平顺县| 岚皋县| 临沂市| 门头沟区| 宕昌县| 上杭县| 敦煌市| 嵊泗县| 苍梧县| 综艺| 南昌市| 宜章县| 台江县| 陕西省|