application对象实现网站计数器
2015-08-14 14:32
399 查看
<body> <% Object oCount = application.getAttribute("count"); //取得count属性值,如果还没有改属性则返回null; Integer count=null; if(oCount==null){ count = new Integer(1); //新建一个Integer对象,因为这是首个访问者,所以包含值1 application.setAttribute("count", count); //为application对象增加count属性并制定其值; }else{ count = (Integer)application.getAttribute("count"); count = new Integer(count.intValue()+1); //将count对象包含的值增加1 application.setAttribute("count", count); //把增加后的新count对象赋值到application对象的count属性 } %> <br> <h3>尊敬的房客,您好!欢迎您的到来!</h3> 您是这里的第<font color="red"><%=count.intValue() %></font>位访客,祝您玩得快乐! </body>
上述代码主要使用了application对象的两个方法,一个“Object getAttribute(String name)”返回给定名的属性值,
另一个是“void setAttribute("String name","Object obj")”设定属性的属性值。
相关文章推荐
- Android笔记:内部类
- mac 下卸载android studio
- 最近刚学到容器Vector,就顺便编写了两个简单的小程序
- IOStime处理
- 教你如何使用WatchKit创建可选列表App
- 让cocos2dx支持并通过arm64 编译
- Apple-Watch开发1
- Android 自定义带回调的Dialog 及EditText相关
- 用在计时器上的“神器”------Timer
- ios中将view转为image
- 【Android学习笔记】【Android学习资源】GitHub上史上最全的Android开源项目分类汇总
- 如何退出Activity?如何安全退出已调用多个Activity的Application?
- 【IOS】ios8推送消息注册
- 几个移动App测试工具
- IOS AFNetWorking 下载文件 断点续传
- IOS8 设置TableView Separatorinset 分割线从边框顶端开始
- android 图片压缩方法
- Android-Xml序列化器生成短信xml文件
- Android中的Selector的用法
- Cubietruck---3. android编译命令分析