三(6)、JSP九大内置对象——application
来源:互联网 发布:百度云域名注册 编辑:程序博客网 时间:2024/06/06 17:31
- application
- 一几个常用的方法
- 二重要的用法
- 三application的一个计数器
- application
application
application对象实现了用户数据的共享。可存放全局变量。生命周期开始于服务器启动,结束于服务器的关闭,在关闭前是一直存在的;这样在用户的前后连接或不同用户之间的连接中,可以对此对象的同一属性进行操作,在任何地方对此对象属性的操作,都将影响到其他用户对此的访问,服务器的启动和关闭 决定了application对象的生命。
服务器启动时产生了application对象,当客户浏览网站的各个页面,application都是同一个,所有客户都是访问共用这个内置对象。
一、几个常用的方法
服务器信息:<%= application.getServerInfo() %> 用户名称:<%= application.getServletContextName() %>
二、重要的用法
1.设置和取application
<!--返回与此会话中指定名称绑定在一起的对象counter,如果没有对象绑定在该名称下,返回null--><%Object obj=application.getAttribute("counter");%><!--使用指定名称将对象绑定counter中--><%application.setAttribute("counter", new Integer(1));%>
2.获取application所有属性
<%Enumeration a=application.getAttributeNames();%>
例子
<% application.setAttribute("city","厦门"); application.setAttribute("postcode","10000"); application.setAttribute("email","123@qq.com"); %> 获取城市:<%=application.getAttribute("city") %> 显示application中所有属性: <% Enumeration a=application.getAttributeNames(); while(a.hasMoreElements()){ out.println(a.nextElement()+" <br>"); } %>
(1)hasMoreElements
boolean hasMoreElements()测试此枚举是否包含更多的元素。
返回:
当且仅当此枚举对象至少还包含一个可提供的元素时,才返回 true;否则返回 false。
(2)nextElement
E nextElement()如果此枚举对象至少还有一个可提供的元素,则返回此枚举的下一个元素。
返回:
此枚举的下一个元素。
3.删除application内容
<% application.removeAttribute("usernae"); application.removeAttribute("password");%>
三、application的一个计数器
<% Object obj=application.getAttribute("counter");//在application中取得couter if(obj==null){ application.setAttribute("counter",new Integer(1));//将1赋值给counter,存储在application中 out.println("该页面访问了1次</br>"); } else{ int counterValue=Integer.parseInt(obj.toString());//解析成十进制的数,toString()返回此对象的字符串表示形式 counterValue++; out.println("该页面访问了"+counterValue+"次</br>"); application.setAttribute("counter",counterValue); } %>
阅读全文
0 0
- 三(6)、JSP九大内置对象——application
- JSP——九大内置对象
- 三(2)、JSP九大内置对象——request(重要)
- 三(4)、JSP九大内置对象——response
- 三(5)、JSP九大内置对象——session
- 三(7)、JSP九大内置对象——config
- 三(8)、JSP九大内置对象——page
- 三(9)、JSP九大内置对象——pageContext
- 三(3)、JSP九大内置对象——exception
- 三(1)、JSP九大内置对象——out
- JSP九大内置对象(三)
- JSP九大内置对象详解(三)
- jsp九大内置对象之application对象
- jsp九大内置对象(二)
- JSP——基础语法和九大内置对象
- JSP学习——九大内置对象
- JSP九大内置对象
- JSP内置九大对象
- poj 2985 The k-th Largest Group (Treap+并查集)
- python3与2的区别
- Hbase shell 命令
- Spring事务管理
- linux系统服务状态
- 三(6)、JSP九大内置对象——application
- xml之JDOM解析(含乱码处理)
- ubuntu修改为阿里源
- 黑盒测试与白盒测试
- firefox浏览器一分钟去广告--去广告插件安装教程(adblock plus)
- 集合框架(数据结构之链表二)--------(上一篇补充)
- 深入学习Java之HashMap
- UVA
- jQuery-强大的jQuery选择器 (详解)