application的使用(实现计数器)


 

application在整个WEB项目中共享使用数据。

常用方法:
 getAttribute();
 setAttribute();
示列:

 

 <%
    Object count=application.getAttribute("count");
    if(count==null){
     //application中未存放count
     application.setAttribute("count", new Integer(1));
    }else{
     //application中已经存放count
     Integer i=(Integer)count;
     application.setAttribute("count", i.intValue()+1);
    }
    Integer icount=(Integer)application.getAttribute("count");
    out.println("页面被访问了"+icount.intValue()+"次");
    %>

 

可以直接将此段代码放在需要显示的JSP页面中。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM