当前位置 : 主页 > 编程语言 > java >

JSP统计访问量的两种方式

来源:互联网 收集:自由互联 发布时间:2021-06-25
1.一次会话算一次访问。 % ! int i = 0 ; % % if (session.isNew()){ i ++ ; } % p 访问方式:一次会话算一次访问。 nbsp;nbsp;nbsp;nbsp; 当前浏览量: % = i % / p 2.刷新一次网页增加一次浏览量: % Integer

1.一次会话算一次访问。

 <%! int i = 0;%>
 <%
    if(session.isNew()){
      i++;
    }
%>
<p>访问方式:一次会话算一次访问。&nbsp;&nbsp;&nbsp;&nbsp;当前浏览量:<%=i %></p>

2.刷新一次网页增加一次浏览量:

<%
  Integer count=(Integer)application.getAttribute("count");
  if(count==null){
     count=1;
  }
  application.setAttribute("count", count+1);
%>
<p>访问方式:刷新一次网页算一次访问。&nbsp;&nbsp;&nbsp;&nbsp;当前浏览量:<%=count %></p>
网友评论