1、session:一個client在訪問網站期間共享
2、application:多個client訪問網站期間共享
3、pageContext:一個頁面之間共享
4、equest:請求
application.setAttribute("屬性名","屬性值");
application.getAttribute("屬性名");
application.removeAttribute("屬性名");
application.getAttributeNames();返回數據類型為:Enumeration
getMajorVersion
功能:返回服務器解釋引擎所支持的最新Seervlet API版本
getMimeType(String file)
功能:返回文件file的文件格式與編碼方式;
getRealPath(String path)
功能:返回虛擬路徑path的真實路徑;
getServerInfo()
功能:返回服務器解釋引擎的信息
5、Enumeration接口
Enumertion接口中僅定義了下面兩個方法。
·boolean hasMoreElemerts()
測試Enumeration枚舉對象中是否還含有元素,如果返回true,則表示還含有至少一個的元素。
·Object nextElement()
如果Bnumeration枚舉對象還含有元素,該方法得到對象中的下一個元素。
准備工作就緒。
現在實現統計網站的訪問量,並且還要打印出網站所有訪問者的sessionID
<%@ page import="java.util.*" contentType="text/html;charset=UTF-8"%>
<%! int numbers = 0;%>
<%! public synchronized void countPeople(){
numbers++;
}%>
<%
if(session.isNew()){
countPeople();
String str = String.valueOf(numbers);
session.setAttribute("count",str);
}
application.setAttribute(session.getId(),Integer.toString(numbers));
Enumeration e = application.getAttributeNames();
while(e.hasMoreElements()){
out.println(e.nextElement().toString()+"
");
}
%>
你的sessionID為<%=session.getId()%> 你是第<%=(String)session.getAttribute("count")%>個訪問本站的人。