JSP教程--Application 的应用详解
发布时间:2023-05-30 14:37:18 所属栏目:教程 来源:
导读: 在前一篇里我们讲了在jsp 中使用session 来保存每个用户的私有信息,但有时服务器需要管理面向整个应用的参数,使得每个客户都能获得同样的参数值。那在jsp中应怎么办呢?和session 一样, jsp使用application 对象
在前一篇里我们讲了在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 <html> <head> <title> new document </title> <body bgcolor="#ffffff"> <% application.setattribute("counter",new integer(0)); out.println(application.getattribute("counter")); %> </body> </html> count.jsp <html> <head> <title> new document </title> </head> <body bgcolor="#ffffff"> <% integer i=(integer)application.getattribute("counter"); i=new integer(i.intvalue()+1); application.setattribute("counter",i); out.println((integer)application.getattribute("counter")); %> </body> </html> (编辑:聊城站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
站长推荐