J 教程--A lication的应用

文章作者 100test 发表时间 2007:09:20 13:06:42
来源 100Test.Com百考试题网


在前一篇里我们讲了在JSP 中使用session 来保存每个用户的私有信息,但有时服务器需要管理面向整个应用的参数,使得每个客户都能获得同样的参数值。那在JSP中应怎么办呢?和Session 一样, JSP使用Application 对象,操作的方法和Session "Times New Roman"一样。

   其API 使用如下:

   Application .setAttribute("Item", ItemValue). //设置一个应用变量

   Integer i=(Integer) Application.getAttribute("ItemName"). // 得到//item

   现以一个简单统计在线人数的的例子来说明Application的应用(这里不考虑离开的情况),init.jsp(初始化),count.jsp( 统计总人数并输出)。

init.jsp


New Document

<%
application.setAttribute("counter",new Integer(0)).
out.println(application.getAttribute("counter")).
%>


count.jsp


New Document


<%
Integer i=(Integer)application.getAttribute("counter").
i=new Integer(i.intValue() 1).
application.setAttribute("counter",i).
out.println((Integer)application.getAttribute("counter")).
%>



相关文章


时间显示控制四板斧
深入理解和改进J _Servlet会话管理机制
在Window T4.0上安装Apache Servlet j
在J 页面中实现检索数据的分页显示
J 教程--A lication的应用
如何使用Java中的Date和Calendar类
J 环境的配置过程(JDK TOMCAT MYSQL)
技术摘要:如何编写安全的Java代码
Hibernate3.x过滤器的高级应用
澳大利亚华人论坛
考好网
日本华人论坛
华人移民留学论坛
英国华人论坛