那位大虾帮忙看哈这个计数器
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>