| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 649 人关注过本帖
标题:那位大虾帮忙看哈这个计数器
取消只看楼主 加入收藏
wei_fan
Rank: 1
等 级:新手上路
帖 子:52
专家分:0
注 册:2008-10-16
结帖率:100%
收藏
 问题点数:0 回复次数:0 
那位大虾帮忙看哈这个计数器
create table total(
int total)

create table counter(
date char(6),
today int,
first int,
second int,
third int,
forth int,
fifth int,
sixth int
)

下面是count.jsp代码 运行后没刷新一次 总访问量total变成0了,但是当日的访问人数去会增加,这是怎么回事啊?

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.

<%@page import="java.util.GregorianCalendar"%>
<%@page import="java.util.Calendar"%>
<%@include file="opendata1.jsp"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
    request.getSession(true);
    int month, day, hour, today = 0, total = 0, select;
    String time;
    GregorianCalendar calendar = new GregorianCalendar();
    month = calendar.get(Calendar.MONTH) + 1;
    day = calendar.get(Calendar.DAY_OF_MONTH);
    hour = calendar.get(Calendar.HOUR_OF_DAY);
    time = "m" + month + "d" + day;
    sql = "select * from counter where date='" + time + "'";
    rs = smt.executeQuery(sql);
    if (!rs.next()) {
        sql = "insert into counter(date,today,first,second,third,forth,fifth,sixth) values('"
                + time + "',0,0,0,0,0,0,0)";
        smt.execute(sql);
    }
    // out.println(time);
    sql = "select * from counter where date='" + time + "'";
    rs = smt.executeQuery(sql);
    if (rs.next()) {
        //out.println("kkkkk"+rs.getString("today"));
        today = rs.getInt(2);
    }
    select = (int) Math.floor(hour / 4) + 1;
    sql = "select count(*) from total";

    if (rs.next()) {
        rs = smt.executeQuery(sql);
        total = rs.getInt(1);
    }
    //out.println("dddd"+total);
    //out.println(select);

    if (session.isNew()) {
        today++;
        switch (select) {
        case 1:
            sql = "update counter set today=" + today
                    + ",first=first+1 where date='" + time + "'";
            smt.execute(sql);
            break;

        case 2:
            sql = "update counter set today=" + today
                    + ",second=second+1 where date='" + time + "'";
            smt.execute(sql);
            break;

        case 3:
            sql = "update counter set today=" + today
                    + ",third=third+1 where date='" + time + "'";
            smt.execute(sql);
            break;

        case 4:
            sql = "update counter set today=" + today
                    + ",forth=forth+1 where date='" + time + "'";
            smt.execute(sql);
            break;
        case 5:
            sql = "update counter set today=" + today
                    + ",fifth=fifth+1 where date='" + time + "'";
            smt.execute(sql);
            break;
        case 6:
            sql = "update counter set today=" + today
                    + ",sixth=sixth+1 where date='" + time + "'";
            smt.execute(sql);
            break;
        }
        total++;
        sql = "update total set total=total+1";
        smt.execute(sql);
        smt.close();
        conn.close();

    }
%>

<h3>你是本站的第<%=total%>位访问者</h3>
<h3>你是今天的第<%=today%>位访问者</h3>
</body>
</html>
搜索更多相关主题的帖子: 计数器 
2009-09-09 12:04
快速回复:那位大虾帮忙看哈这个计数器
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.035767 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved