counterapp1.jsp

来自「jsp……」· JSP 代码 · 共 29 行

JSP
29
字号
<%@ page contentType="text/html;charset=GB2312" %>
<HTML>
<head>
<title>网站计数器</title>
</head>
<BODY>
    <%!   
     synchronized void countPeople()//串行化计数函数
        {  ServletContext  application=getServletContext();
           Integer number=(Integer)application.getAttribute("Count");
           if(number==null)  //如果是第1个访问本站
              { number=new Integer(1);
                application.setAttribute("Count",number); 
              }
           else
              { number=new Integer(number.intValue()+1);
                application.setAttribute("Count",number); 
              }
        }
    %>
    <% if(session.isNew())//如果是一个新的会话
          countPeople();
       Integer yourNumber=(Integer)application.getAttribute("Count");
    %>
<P><P>欢迎访问本站,您是第
    <%=yourNumber%>
个访问用户。
</BODY>
</HTML>

⌨️ 快捷键说明

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