⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 view.jsp

📁 一个用java编译的流量统计系统
💻 JSP
字号:
<%@ page import="java.sql.*,Db_sql"%>
<%@ page import="java.io.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.util.Date"%>
<%@ page import="DBConnStat"%>

<%
String strSql;

Db_sql db = null;
Hashtable countresult = new Hashtable();
String typename = "";
String username = "";
String email = "";
String webname = "";
String url = "";
String sTemp = "";
int iCount = 0;
int perdayhits = 0;
int pdayhits = 0;
int iTemp = 0;
int torder = 0;
int order = 0;
//int iUid = 0;
String iUid = "";
Date dTemp = null;
Hashtable[] client = new Hashtable[25];

try {
    db = new Db_sql(DBConnStat.host,DBConnStat.port,DBConnStat.sid,DBConnStat.user,DBConnStat.password);
  iUid = request.getParameter("uid");

  strSql = " update stat set avghits=round(totalhits/(round(SYSDATE-starttime)+1)) ";
  db.query(strSql);
  
  strSql = " select id,puid,starttime,totalhits,sitetype,maxhits,todayhits, ";
  strSql += " round(SYSDATE-starttime)+1 as days, avghits from stat ";
  strSql += " where puid= '" + iUid + "'";
  

  db.query(strSql);
  if (db.next())
  {
    countresult.put("id",new Integer(db.getInt("id")));
    countresult.put("puid",db.getString("puid"));
    countresult.put("starttime",db.getDate("starttime"));
    countresult.put("totalhits",new Integer(db.getInt("totalhits")));
    countresult.put("sitetype",db.getString("sitetype"));
    countresult.put("todayhits",new Integer(db.getInt("todayhits")));
    countresult.put("maxhits",new Integer(db.getInt("maxhits")));
    countresult.put("avghits",new Integer(db.getInt("avghits")));
    countresult.put("days",new Integer(db.getInt("days")));
    
    //-------------取得站点类型-------------------------
    typename = (String)countresult.get("sitetype");
    
    //------------计算平均每天浏览量----------------------
    iTemp = ((Integer)countresult.get("days")).intValue();
    
    if (iTemp != 0)
      perdayhits = ((Integer)countresult.get("totalhits")).intValue()/iTemp;
    else
      perdayhits = ((Integer)countresult.get("todayhits")).intValue();
      
    //-----------得到用户的邮件和名字 站名 url----------------------  
    strSql = " select username,email,title ";
    strSql += " from userinfo where username= '" + iUid + "'";
    db.query(strSql);
    if (db.next())
    {
      username = db.getString("username");
      email = db.getString("email");
      webname = db.getString("title");
      url = "http://" + iUid + ".at.china.com";
    }

    //-----------计算在同类网站中目前平均排名-----------------
    strSql = "select count(*) as above_count from stat where avghits>";
    strSql += (Integer)countresult.get("avghits");
    strSql += " and sitetype='" + (String)countresult.get("sitetype") + "'";
    db.query(strSql);
    db.next();
    torder = db.getInt("above_count") + 1;
    
    //----------计算在所有网站中平均排名--------------------
    strSql = "select count(*) as above_count from stat where avghits>";
    strSql += (Integer)countresult.get("avghits");
    db.query(strSql);
    db.next();
    order = db.getInt("above_count") + 1;

    //-----------预计本日浏览人数----------------------- 
    dTemp = new Date();
    iTemp = ((Integer)countresult.get("todayhits")).intValue();
    if ((dTemp.getHours()*60 + dTemp.getMinutes()) != 0)
    {
      pdayhits = (new Float(((float)iTemp/(dTemp.getHours()*60 + dTemp.getMinutes())) *24*60)).intValue();
    }
    else
    {
      pdayhits = perdayhits;
    }
      
    //-----------读取最近25位访问者--------------------
    strSql =  "select id,puid,ip,browser,os,ip,to_char(thedate,'yyyy-mm-dd') as thedate, ";
    strSql += " to_char(thedate,'hh24:mi:ss') as thetime from statdetail ";
    strSql += "where puid='" + iUid + "' order by thedate desc";

    db.query(strSql);
    
    for (iCount = 0;db.next();iCount++)
    {
      if (iCount >= 25) break;
      client[iCount] = new Hashtable();
      sTemp = db.getString("thedate");
      client[iCount].put("thedate",sTemp);
      sTemp = db.getString("thetime");
      client[iCount].put("thetime",sTemp);
      client[iCount].put("ip",db.getString("ip"));
      client[iCount].put("browser",db.getString("browser"));
      client[iCount].put("os",db.getString("os"));
    }
  }
  
} catch(Exception e)
{
  //out.println(e);
} finally
{
  try { db.close(); } catch(Exception e) {}
}
%>
<HTML>
<HEAD>
<TITLE>home4u.china.com</TITLE>
<META content="text/html; charset=gb2312" http-equiv=Content-Type>
<LINK 
href="images/cool.css" rel=stylesheet title=cool type=text/css>
<META content="MSHTML 5.00.2614.3500" name=GENERATOR>
<style type="text/css">
<!--
-->
</style>
</HEAD>

<BODY bgColor=#FFFFFF link="#003366" vlink="#003366" alink="#003366">
<div align="center"><center>

  <table width="611" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr> 
      <td width="163"><a href="http://home4u.china.com/" target=_blank><img src="images/logohome.gif" width="143" height="87" border="0"></a></td>
      <td width="437"><a href="http://home4u.china.com/" target=_blank><img 
alt=申请home4u border=0 height=60 src="http://home4u.china.com/images/home4ubanner.gif" 
width=468></a></td>
    </tr>
  </table>
  <table width="611" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
      <td><img src="images/topedge.gif" width="611" height="9"></td>
    </tr>
  </table>

  <table width="611" border="0" align="center" cellspacing="0" bgcolor="#FFE8D0">
    <tr> 
      <td width="292"><font color="#FFE8D0">--</font>
      <a href=<%="\"hourstat.jsp?uid=" + iUid + "\""%>>小时统计</a>&nbsp; 
      <a href=<%="\"daystat.jsp?uid=" + iUid + "\""%>>日统计</a>&nbsp; 
      <a href=<%="\"weekstat.jsp?uid=" + iUid + "\""%>>周统计</a> 
      <a href=<%="\"monthstat.jsp?uid=" + iUid + "\""%>>月统计</a>
      <a href=<%="\"purl.jsp?uid=" + iUid + "\""%>>来路显示</a>&nbsp; 
      </td>
      <td width="315"> 
        <div align="right">
   <%
   sTemp  = "站名:<a href=\"" + url + "\">";
   sTemp += webname + "</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
   sTemp += "站长:" + "<a href=\"mailto:" + email + "\">";
   sTemp += username + "</a>";
   out.println(sTemp);
   %>
        </div>
      </td>
    </tr>

 <TR>
    <TD colSpan=2>
      <TABLE align=center border=1 borderColor=#ffb56a cellPadding=0 
      cellSpacing=0 class=tt3 width="96%">
        <TBODY>
        <TR>
          <TD>
            <TABLE border=0 cellPadding=3 cellSpacing=0 class=tt3 
              width="100%"><TBODY>
              <TR bgColor=#ffb56a>
                <TD bgColor=#ffb56a colSpan=2 width="100%"><FONT 
                  color=#ffffff>综 合 数 据</FONT></TD></TR>
              <TR bgColor=#dddddd>
                <TD align=left bgColor=#dddddd width="60%">
                  <P class=sureyeah>开始统计日期 </P></TD>
                <td align="right" width="40%"><font color="#336699" >
                <% 
                  try {
                    out.println((Date)countresult.get("starttime"));
                  } catch (Exception e) { out.println(e); }
                %> 
                    
                </font></td>
              </tr>
              <tr bgColor="#ffffff">
                <td align="left" width="60%">总统计天数</td>
                <td align="right" width="40%"><font color="#336699" ><% out.println((Integer)countresult.get("days")); %></font></td>
              </tr>
              <tr bgColor="#cccccc">
                <td align="left" width="60%">总浏览人数</td>
                <td align="middle" width="40%"><p align="right"><font color="#336699" ><% out.println((Integer)countresult.get("totalhits")); %></font></td>
              </tr>
              <tr bgColor="#ffffff">
                <td align="left" width="60%">平均每天访问人数</td>
                <td align="right" width="40%"><font color="#336699" ><% out.println(perdayhits); %></font></td>
              </tr>
              <tr bgColor="#cccccc">
                <td align="left" width="60%">站点性质</td>
                <td align="right" width="40%"><font color="#336699" ><% out.println(typename); %></font></td>
              </tr>
              <tr bgColor="#cccccc">
                <td align="left" width="60%">目前同类站点中平均排名</td>
                <td align="right" width="40%"><font color="#336699" >第 <% out.println(torder); %> 名</font></td>
              </tr>
              <tr bgColor="#ffffff">
                <td align="left" width="60%">目前总平均排名</td>
                <td align="right" width="40%"><font color="#336699" >第 <% out.println(order); %> 名</font></td>
              </tr>
              <tr bgColor="#ffffff">
                <td align="left" width="60%">今日总浏览人数</td>
                <td align="right" width="40%"><font color="#336699" ><% out.println((Integer)countresult.get("todayhits")); %></font></td>
              </tr>
              <tr bgColor="#cccccc">
                <td align="left" width="60%">预计本日浏览人数</td>
                <td align="right" width="40%"><font color="#336699" ><% out.println(pdayhits); %></font></td>
              </tr>
              <tr bgColor="#ffffff">
                <td align="left" width="60%">最高一天浏览量</td>
                <td align="right" width="40%"><font color="#336699" ><% out.println((Integer)countresult.get("maxhits")); %></font></td>
              </tr>
             </TBODY>
            </table>
           </td>
         </tr>
        </table>            
        </td>
      </tr>
  <tr>
  <td colSpan=2>
  <TABLE align=center border=1 borderColor=#ffb56a cellPadding=0 
      cellSpacing=0 class=tt3 width="96%">
        <TBODY>
        <TR>
          <TD>
            <TABLE border=0 cellPadding=3 cellSpacing=0 class=tt3 height=155 
            width="100%">
<TBODY>
          <tr>
            <TD bgColor=#ffb56a colSpan=6 width="100%"><font
            color="#ffffff"><% out.println("最 后 " + iCount + " 位 访 问 者"); %></font></td>
          </tr>
          <tr bgColor="#cccccc">
            <td align="middle">日期</td>
            <td align="left"><p align="center">时间</td>
            <td align="left"><p align="enter">访客IP</td>
            <td align="left"><p align="center">浏览器</td>
            <td align="right"><p align="center">操作系统</td>
          </tr>
          <%  int i=0; %>
          <%  while(i<iCount) {%>
          <%try {%>
          <tr bgColor="#ffffff">
            <td align="middle"  noWrap ><% out.println((String)client[i].get("thedate")); %></td>
            <td align="middle"  noWrap ><% out.println((String)client[i].get("thetime")); %></td>
            <td align="left"   noWrap ><p align="center"><% out.println((String)client[i].get("ip")); %></td>
            <td align="left"  noWrap ><p align="center"><font color="#000000"><% out.println((String)client[i].get("browser")); %></font></td>
            <td align="left"   noWrap ><p align="center"><font color="#336699"><% out.println((String)client[i].get("os")); %></font></td>
          <%} catch (Exception e) { out.println(e); } %>
          </tr>
          <% i++;
            }   %>

</TBODY>
        </table>
        </td>
      </tr>
</TBODY>
    </table>
    </td>
  </tr>
</table>
</center></div>
<TABLE align=center border=0 cellPadding=8 cellSpacing=0 width=510>
  <TBODY>
  <TR>
    <TD>
      <DIV align=center>
      <DIV align=left></DIV>Copyright2000 <A href="http://www.china.com/" 
      target=_blank>http://www.china.com/</A> All Rights 
  Reserved</DIV></TD></TR></TBODY></TABLE>
  <p><p>
</body>
</html>


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -