JSP编写访问当前网站页面以及子页面子的访问次数同时总访问次数自加

2011年11月1日 17:36:42     开始   以下代码仅供参考

 

 index.jsp

 

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<%
 int i = 1;
%>
<%
 Object count = application.getAttribute("count");
 Object count1 = application.getAttribute("count1");
 Object count2 = application.getAttribute("count2");
%>
<%
 if (count == null) {
  application.setAttribute("count", i);
%>
<%
 } else {
  application.setAttribute("count", (Integer) (count) + 1);
 }
%>
首页访问次数:<%=count%>
<h1><a href="index2.jsp">第一页面</a></h1><h2>访问量</h2><%=count1 %><br/>
<h1><a href="index3.jsp">第二页面</a></h1><h2>访问量</h2><%=count2 %>

 

 

index2,jsp

 

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<%
 int j = 1;
%>
<%
Object count = application.getAttribute("count");
 Object count1 = application.getAttribute("count1");
%>
<%
 if (count1 == null) {
  application.setAttribute("count1", j);
%>
<%
 } else {
  application.setAttribute("count1", (Integer) (count1) + 1);
  application.setAttribute("count", (Integer) (count) + 1);
 }
%>
分页一访问次数:<%=count1%><br/>
网站访问量:<%=count%>

 

 

index3.jsp

 

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<%
 int k = 1;
%>
<%
Object count = application.getAttribute("count");
 Object count2 = application.getAttribute("count2");
%>
<%
 if (count2 == null) {
  application.setAttribute("count2", k);
%>
<%
 } else {
  application.setAttribute("count2", (Integer) (count2) + 1);
  application.setAttribute("count", (Integer) (count) + 1);
 }
%>
分页二访问次数:<%=count2%>
网站访问量:<%=count%>

 

 

2011年11月1日 17:37:04  结束 以上代码仅供参考
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值