jsp之application

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

[java]  view plain copy print ?
  1. <span style="font-size:18px;"><%@ page import="java.util.*" contentType="text/html;charset=UTF-8"%>  
  2. <%! int numbers = 0;%>  
  3. <%! public synchronized void countPeople(){  
  4.         numbers++;  
  5. }%>  
  6. <%  
  7.         if(session.isNew()){  
  8.                 countPeople();  
  9.                 String str = String.valueOf(numbers);  
  10.                 session.setAttribute("count",str);  
  11.         }  
  12.         application.setAttribute(session.getId(),Integer.toString(numbers));  
  13.         Enumeration e = application.getAttributeNames();  
  14.         while(e.hasMoreElements()){  
  15.                 out.println(e.nextElement().toString()+"<br>");  
  16.         }  
  17. %>  
  18.   
  19. <html>  
  20.         你的sessionID为<%=session.getId()%>  
  21.         你是第<%=(String)session.getAttribute("count")%>个访问本站的人。  
  22. </html>  
  23. </span>  

出现的问题:该开始没有引用java.util.*这个包,导致Enumeration不能用。以后写的时候要注意加上包了,
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值