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