美文网首页需要深入研究Code
application对象(获取网站的访问量)(2)

application对象(获取网站的访问量)(2)

作者: 淡写回忆 | 来源:发表于2019-06-08 18:02 被阅读478次

application:提供了关于服务器版本,应用级初始化参数和应用内资源据对路径的方式

application作用域:web容器的生命周期,即多用户登录时的数据可以同时进行访问,如网站的访问量(如果有数据需要在整个web应用程序中进行访问的话使用application中的attribute方法即可)

访问量代码:

if (flag == true){

    Object o = application.getAttribute("count");//获取访问的次数

    if (o == null){ //判断是否为空即为0的情况

        application.setAttribute("count",1);//当访问次数为空时修改为1,存入application中

    }else {

        int count = Integer.parseInt(o.toString());//将获取的object类型的访问次数

        application.setAttribute("count",count + 1);//累加访问的数量

    }

前台显示代码为:

<p align="left">访问量为:<%= application.getAttribute("count")%></p>

显示效果为:

相关文章

网友评论

    本文标题:application对象(获取网站的访问量)(2)

    本文链接:https://www.haomeiwen.com/subject/rioixctx.html