获取访问页面总数量

来源:互联网 发布:java 开源框架 编辑:程序博客网 时间:2024/05/18 00:03

<import="java.util.Set"%>
<import="java.util.HashMap"%>
<import="java.util.Map"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!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>
<%
String ip=request.getRemoteAddr();
Map map=(Map)application.getAttribute("map");
if(map==null){
  map=new HashMap();
}
Integer value=(Integer)map.get(ip);
if(value==null){
  value=1;
}else{
  value=value+1;
}
map.put(ip, value);
application.setAttribute("map", map);
%>
<table>
<caption>网站的访问信息</caption>
<%
  int count=0;
  Set set=map.keySet();
  Object[] keys=set.toArray();
  for(int i=0;i<keys.length;i++){
   Integer c=(Integer)map.get(keys[i]);
   count+=c;
   %>
   <tr>
    <td><%=keys[i] %></td>
    <td><%=c %></td>
   </tr>
   <%
  }
%>
</table>
总访问量<%=count %>
</body>
</html>