网页计数器源码

来源:互联网 发布:知乎不能搜索 编辑:程序博客网 时间:2024/04/28 19:31
<%@ page language="java" pageEncoding="gb2312" %>
<html>
  <head>
     </head>
  <body>
      <%!
          synchronized void countPeople(){
              ServletContext application = getServletContext();
              Integer number = (Integer)application.getAttribute("Count");
              if(number == null){
                  number = new Integer(1);
                  application.setAttribute("Count",number);
              }else{
                  number = new Integer(number.intValue() + 1);
                  application.setAttribute("Count",number);
              }
          }
       %>
       <%
           if(session.isNew()){
               countPeople();
               Integer myNumber = (Integer)application.getAttribute("Count");
              
               session.setAttribute("MyCount",myNumber);
            }
           
        %>
        <P><P>
        <%int a =((Integer)session.getAttribute("MyCount")).intValue(); %>
        您是第<%=a%>访问本站的客户
  </body>
</html>
原创粉丝点击