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

📄 record.jsp

📁 采用JSP+Java Bean开发的基于MySQL数据库的计数器。 包含有动网165501条数据库。 可以限制每个用户记录的IP数
💻 JSP
字号:
<%
/**
* Title:Lerx计数器(JSP+MySQL)
* Description:含有动网最新IP数据库 165501条 2004年11月5日更新,我找到的最新的也最合适的就是这个了,花了些时间处理导入到MySQL里。
* Copyright: Copyright (c) 2005
* Company:www.lerx.com,www.5z.com.cn,www.huafang.com.cn
* @author:lzh@5z.com.cn() QQ:27723812
* @version 1.0
* 开发平台:红旗Linux4.1,JDK 1.5.0_04-b05,Tomcat 5.5.9,MySQL 3.23.58
* 完成时间:2005.12.2
*/
%>
<%@ page contentType="text/html;charset=gb2312" %>
<jsp:useBean id="replace" scope="page" class="forum.StrReplace" />
<%@ page import="java.io.*"%>
<%@ page import="java.util.*" %>
<%@ page import="java.util.Date" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ include file="const.jsp" %>
<%@ include file="conn.jsp" %>
<%
String ps_id="",ps_IP="",ps_add="",ps_station="",ps_referer="",ps_agent="",ps_browser="",ps_os="",ps_doc="",ps_tmp="",ps_SQLCmd="",ps_ImgStr="",ps_MaxIPStr="";
int pi_graph=0,pi_type=0,pi_ScrWidth=0,pi_ScrHeight=0,pi_IPCount=0,pi_FirstIPRecID=0;
int pi_TodayIP=0,pi_TodayView=0,pi_YestodayIP=0,pi_YestodayView=0,pi_MaxIPRec=0,pi_tmp=0;
Timestamp pt_Timestamp=null;
long pl_InitIP=0,pl_CountIP=0,pl_AllIP=0,pl_ViewCount=0,pl_TimeDiff = -1;
double pdb_IPTmp=0;
boolean pb_IPExit=false,pb_IPAdd=false,pb_IPMaxOver=false,pb_continue=false;
Date pd_now = new Date(),pd_LastDateRec=new Date(99,1,1),pd_MaxIPDate=new Date(99,1,1);
java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyy-MM-dd");

request.setCharacterEncoding("GB2312");
ps_id = request.getParameter("user").trim();
pi_graph = Integer.parseInt(request.getParameter("graph").trim());
pi_type = Integer.parseInt(request.getParameter("type").trim());

//取数据库中记录数
ps_SQLCmd="select * from statuser where id='"+ps_id+"'"; 
rs=stmt.executeQuery(ps_SQLCmd);
if (rs.next())
{
pb_continue=true;
pl_InitIP				=rs.getInt("InitIP");
pl_CountIP			=rs.getInt("CoutIP");
pl_ViewCount		=rs.getInt("ViewCount");
pi_TodayIP			=rs.getInt("TodayIP");
pi_TodayView		=rs.getInt("TodayView");
pi_YestodayIP		=rs.getInt("YestodayIP");
pi_YestodayView	=rs.getInt("YestodayView");
pi_MaxIPRec			=rs.getInt("MaxIP");
pd_LastDateRec	=rs.getDate("LastRec");
pl_ViewCount++;
}

rs.close();

if (pb_continue)
{

	//取客户端信息
	ps_IP = request.getRemoteAddr().trim();
	ps_referer = request.getParameter("referrer");
	ps_agent = request.getHeader("User-Agent");
	ps_doc = request.getParameter("CurrentDoc");
	pi_ScrWidth = Integer.valueOf(request.getParameter("screenwidth")).intValue(); 
	pi_ScrHeight = Integer.valueOf(request.getParameter("screenheight")).intValue();
	//IP地址处理

	ps_tmp = replace.str_replace(ps_IP,".",",");
	String[] ps_iptmp=ps_tmp.split(",");
	pdb_IPTmp=(16777216 * (double)Integer.parseInt(ps_iptmp[0])) + (65536 * (double)Integer.parseInt(ps_iptmp[1])) + (256 * (double)Integer.parseInt(ps_iptmp[2])) + (double)Integer.parseInt(ps_iptmp[3]);
	ps_SQLCmd="select * from address where ip1 <= "+pdb_IPTmp+" and ip2 >= "+pdb_IPTmp + " order by ip2-ip1"; 
	rs=stmt.executeQuery(ps_SQLCmd);
	if (rs.next())
	{
		ps_add=rs.getString("country");
		ps_station=rs.getString("city");
		if (ps_add==null)
		{
			ps_add="";
		}
		else
		{
			ps_add=ps_add.trim();
		}
		if (ps_station==null)
		{
			ps_station="";
		}
		else
		{
			ps_station=ps_station.trim();
		}
		if (!ps_station.equals(""))
		{
			ps_add=ps_add+"·"+ps_station;
		}
	}
	else
	{
		ps_add="未知";
		ps_station="";
	}
	rs.close();
	if (ps_add==null)
	{
		ps_add="未知";
	}

	//复制的代码
	ps_browser=ps_agent.split(";")[1].trim();
	ps_os     =ps_agent.split(";")[2].trim();
	ps_agent=ps_agent.toLowerCase();

	if (ps_agent.indexOf("win") > -1)
	{
 
		if (ps_agent.indexOf("windows nt 5.0") > -1 || ps_agent.indexOf("winnt5.0") > -1)
		{
  		ps_os = "Windows 2000";
		}
		if (ps_agent.indexOf("windows nt 5.1") > -1 || ps_agent.indexOf("winnt5.1") > -1)
		{
  		ps_os = "Windows XP";
		}
		if (ps_agent.indexOf("win16") > -1 || ps_agent.indexOf("windows 3.") > -1)
		{
  		ps_os = "Windows 3.x";
		}
	}
	else
	{
		if (ps_agent.indexOf("mac") > -1 || ps_agent.indexOf("powerpc") > -1)
		{
  		ps_os = "Mac";
		}
		if (ps_agent.indexOf("hp-ux") > -1 || ps_agent.indexOf("sunos") > -1 || ps_agent.indexOf("bsd") > -1 || ps_agent.indexOf("osf1") > -1 || ps_agent.indexOf("irix") > -1 || ps_agent.indexOf("aix") > -1)
		{
  		ps_os = "UNIX";
		}
		if (ps_agent.indexOf("linux") > -1)
		{
  		ps_os = "Linux";
		}
	}
	//复制的代码结束


	//检查该用户的IP记录数,pb_IPMaxOver记录是否达到限制
	ps_SQLCmd="select count(*) from ViewRec where userid='" + ps_id + "'";
	rs=stmt.executeQuery(ps_SQLCmd);
	if (rs.next())
	{
		pi_IPCount	=rs.getInt(1);
	}
	rs.close();
	if (pi_IPCount>pi_MaxIP)
	{
		pb_IPMaxOver=true;
		ps_SQLCmd="select * from ViewRec where userid='" + ps_id + "' order by ViewTime asc limit 0,1";
		rs=stmt.executeQuery(ps_SQLCmd);
		if (rs.next())
		{
			pi_FirstIPRecID	=rs.getInt("id");
		}
		rs.close();
	}



	//检查并记录来访者
	ps_SQLCmd="select * from ViewRec where userid='" + ps_id + "' and ip='"+ps_IP+"'";
	rs=stmt.executeQuery(ps_SQLCmd);
	if (rs.next())
	{
		pt_Timestamp=rs.getTimestamp("ViewTime");
		pl_TimeDiff=(pd_now.getTime() - pt_Timestamp.getTime())/(1000*60*60);
		pb_IPExit=true;
		if (pl_TimeDiff>6)
		{
			pb_IPAdd=true;
		}
	}
	else
	{
		pt_Timestamp=null;
		pb_IPAdd=true;
	}
	rs.close();

	//如果有该IP记录
	if (pb_IPExit)
	{
		ps_SQLCmd="update ViewRec set ";
		ps_SQLCmd	=	ps_SQLCmd + "ViewTime=now()";

		if (pb_IPAdd)
		{
			ps_SQLCmd	=	ps_SQLCmd + ",referrer='"+ps_referer+"'";
		}
		ps_SQLCmd	=	ps_SQLCmd + ",fromwhere='"+ps_add+"'";
		ps_SQLCmd	=	ps_SQLCmd + ",CurrentURL='"+ps_doc+"'";
		ps_SQLCmd	=	ps_SQLCmd + ",vos='"+ps_os+"'";
		ps_SQLCmd	=	ps_SQLCmd + ",vbrowser='"+ps_browser+"'";
		ps_SQLCmd	=	ps_SQLCmd + ",scwidth="+pi_ScrWidth;
		ps_SQLCmd	=	ps_SQLCmd + ",scheight="+pi_ScrHeight;
		ps_SQLCmd	=	ps_SQLCmd + " where userid='" + ps_id + "' and ip='"+ps_IP+"'";
		stmt.executeUpdate(ps_SQLCmd);
	}
	//如果没有该IP记录
	else
	{
		if (pb_IPMaxOver)
		{
			ps_SQLCmd="update ViewRec set ";
			ps_SQLCmd	=	ps_SQLCmd + "ViewTime=now()";
			ps_SQLCmd	=	ps_SQLCmd + ",ip='"+ps_IP+"'";
			ps_SQLCmd	=	ps_SQLCmd + ",referrer='"+ps_referer+"'";
			ps_SQLCmd	=	ps_SQLCmd + ",fromwhere='"+ps_add+"'";
			ps_SQLCmd	=	ps_SQLCmd + ",CurrentURL='"+ps_doc+"'";
			ps_SQLCmd	=	ps_SQLCmd + ",vos='"+ps_os+"'";
			ps_SQLCmd	=	ps_SQLCmd + ",vbrowser='"+ps_browser+"'";
			ps_SQLCmd	=	ps_SQLCmd + ",scwidth="+pi_ScrWidth;
			ps_SQLCmd	=	ps_SQLCmd + ",scheight="+pi_ScrHeight;
			ps_SQLCmd	=	ps_SQLCmd + " where userid='" + ps_id + "' and id="+pi_FirstIPRecID;
			stmt.executeUpdate(ps_SQLCmd);
		}
		else
		{
			ps_SQLCmd="insert into ViewRec(userid,ViewTime,ip,fromwhere,CurrentURL,referrer,vos,vbrowser,scwidth,scheight) values('";
			ps_SQLCmd=ps_SQLCmd + ps_id + "'";
			ps_SQLCmd=ps_SQLCmd + ",now()";
			ps_SQLCmd=ps_SQLCmd + ",'" + ps_IP + "'";
			ps_SQLCmd=ps_SQLCmd + ",'" + ps_add + "'";
			ps_SQLCmd=ps_SQLCmd + ",'" + ps_doc + "'";
			ps_SQLCmd=ps_SQLCmd + ",'" + ps_referer + "'";
			ps_SQLCmd=ps_SQLCmd + ",'" + ps_os + "'";
			ps_SQLCmd=ps_SQLCmd + ",'" + ps_browser + "'";
			ps_SQLCmd=ps_SQLCmd + "," + pi_ScrWidth;
			ps_SQLCmd=ps_SQLCmd + "," + pi_ScrHeight;
			ps_SQLCmd=ps_SQLCmd + ")";
			stmt.executeUpdate(ps_SQLCmd);
		}
	}

	//IP计数增加
	if (pb_IPAdd)
	{
		pl_CountIP++;

		if (formatter.format(pd_now).equals(formatter.format(pd_LastDateRec)))
		{
			pi_TodayIP++;
			pi_TodayView++;
			if (pi_MaxIPRec<pi_TodayIP)
				{
					pi_MaxIPRec	=	pi_TodayIP;
					ps_MaxIPStr	=	",MaxIPDate=\'"+formatter.format(pd_now)+"\',MaxIP="+pi_MaxIPRec;
				}
	
		}
		else
		{
			pi_YestodayIP=pi_TodayIP;
			pi_TodayIP=1;
			pi_YestodayView=pi_TodayView;
			pi_TodayView=1;
	
			//判断是否为最高记录
			if (pi_MaxIPRec<pi_YestodayIP)
			{
				pi_MaxIPRec	=	pi_YestodayIP;
				ps_MaxIPStr	=	",MaxIPDate=\'"+formatter.format(pd_LastDateRec)+"\',MaxIP="+pi_MaxIPRec;
			}
			pd_LastDateRec=pd_now;
		}
	}
	else
	{
		if (formatter.format(pd_now).equals(formatter.format(pd_LastDateRec)))
		{
			pi_TodayView++;
		}
		else
		{
			pi_YestodayIP=pi_TodayIP;
			pi_TodayIP=0;
			if (pi_MaxIPRec<pi_YestodayIP)
			{
				pi_MaxIPRec	=	pi_YestodayIP;
				ps_MaxIPStr	=	",MaxIPDate=\'"+formatter.format(pd_LastDateRec)+"\',MaxIP="+pi_MaxIPRec;
			}
			pi_YestodayView=pi_TodayView;
			pi_TodayView=1;
			pd_LastDateRec=pd_now;
		}
	}

	//保存记录
	ps_SQLCmd = "update statuser set CoutIP="+pl_CountIP;
	ps_SQLCmd = ps_SQLCmd + ",ViewCount="+pl_ViewCount;
	ps_SQLCmd = ps_SQLCmd + ",LastRec=\'"+formatter.format(pd_LastDateRec);
	ps_SQLCmd = ps_SQLCmd + "\',YestodayIP="+pi_YestodayIP;
	ps_SQLCmd = ps_SQLCmd + ps_MaxIPStr;
	ps_SQLCmd = ps_SQLCmd + ",TodayIP="+pi_TodayIP;
	ps_SQLCmd = ps_SQLCmd + ",TodayView="+pi_TodayView;
	ps_SQLCmd = ps_SQLCmd + ",YestodayView="+pi_YestodayView;
	ps_SQLCmd = ps_SQLCmd + " where id='" + ps_id + "'";

	stmt.executeUpdate(ps_SQLCmd);

%>

<%
	pl_AllIP=pl_CountIP+pl_InitIP;
	String ps_tokens = String.valueOf(pl_AllIP);
  ps_tokens = ps_tokens.trim();
  if (ps_tokens.length()<6)
  {
  	pi_tmp=6 - ps_tokens.length();
  	for (int i=0;i<pi_tmp;i++)
  	{
  		ps_tokens="0"+ps_tokens;
  	}
  }
%>

<%
switch (pi_type)
{
	case 1:
		
		out.println("document.write(\"<a target=_blank href="+ps_RootPath+"detail.jsp?id="+ps_id+">"+ps_tokens+"</a>\");");
		break;
	case 2:
		break;
	case 3:
	out.println("document.write(\"<a target=_blank href="+ps_RootPath+"detail.jsp?id="+ps_id+"><img border=0 src="+ps_RootPath+"images/lerx.jpg></a>\");");
		break;
	default:
		   
   	for (int i=0;i<ps_tokens.length();i++)
   	{
      ps_ImgStr += "<img src="+ps_RootPath+"images/"+String.valueOf(pi_graph)+ "/" + ps_tokens.charAt(i) + ".gif border=0>";
   	}
  	out.println("document.write(\"<a target=_blank href="+ps_RootPath+"detail.jsp?id="+ps_id+">"+ps_ImgStr+"</a>\");");
}
	
}
%>
<%@ include file="disconn.jsp" %>

⌨️ 快捷键说明

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