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頁面中。