JSP专题

Application对象实现网页计数器

2018-08-17  本文已影响0人  神坛下的我

index.jsp

<body>
    <%
        int i=0;
        synchronized(application){
            if(application.getAttribute("times")==null){
                i=1;
            }
            else{
                i=Integer.parseInt((String)application.getAttribute("times"));
            }
            application.setAttribute("times", Integer.toString(i));
        }
    %>
    <table>
        <tr bgcolor="lightgrey">
        <td align="center">欢迎访问!</td>
        </tr>
        <tr>
        <td align="center">
            您是第<b><%=i %></b>位访问本网站的游客!
        </td></tr>
    </table>
</body>
15.PNG 16.PNG 17.PNG
上一篇 下一篇

猜你喜欢

热点阅读