标签:java jsp application session
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
<span style="font-size:18px;"><%@ 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()+"<br>");
}
%>
<html>
你的sessionID为<%=session.getId()%>
你是第<%=(String)session.getAttribute("count")%>个访问本站的人。
</html>
</span>标签:java jsp application session
原文地址:http://blog.csdn.net/havedream_one/article/details/45047987