当前位置:网站首页>JSP application对象简介说明
JSP application对象简介说明
2022-07-31 08:23:00 【qq_25073223】
下文笔者讲述JSP中application对象的相关简介说明,如下所示:
application对象: 是一个应用程序对象 当Web服务器启动时 Web服务器会自动创建一个application对象 application对象一旦创建,它将一直存在,直到Web服务器关闭 即:application对象的生命周期为Web服务器启动到Web服务器关闭 ---------------------------------------------------------------- application对象的作用范围: 它是一个应用程序级的对象,它作用于整个Web应用程序, 所有的客户端都共享一个application对象 ------------------------------------------------------------------- 注意事项: application的生命周期比request及session都要长 只要web服务器未关闭或停止,则applicatoin中数据会一直存在
application对象中的方法
| String getAttribute(String name) | 根据属性名称获取属性值 |
| Enumeration getAttributeNames() | 获取所有的属性名称 |
| void setAttribute(String name, Object object) | 设置属性,指定属性名称和属性值 |
| void removeAttribute(String name) | 根据属性名称删除对应的属性 |
| ServletContext getContext(String uripath) | 获取指定URL的ServletContext对象 |
| String getContextPath() | 获取当前Web应用程序的根目录 |
| String getInitParameter(String name) | 根据初始化参数名称,获取初始化参数值 |
| int getMajorVersion() | 获取Servlet API的主版本号 |
| int getMinorVersion() | 获取Servlet API的次版本号 |
| String getMimeType(String file) | 获取指定文件的MIME 类型 |
| String getServletInfo() | 获取当前Web服务器的版本信息 |
| String getServletContextName() | 获取当前Web应用程序的名称 |
| void log(String message) | 将信息写入日志文件中 |
例
获取网站的访问次数
<%@ page import="java.util.*" contentType="text/html;charset=UTF-8"%>
<%! int numbers = 0;%>
<%! public synchronized void count(){
numbers++;
}%>
<%
if(session.isNew()){
count();
String str = String.valueOf(numbers);
session.setAttribute("count",str);
}
application.setAttribute(session.getId(),Integer.toString(numbers));
Enumeration e = application.getAttributeNames();
while(e.hasMoreElements()){
out.println(e.nextElement().toString()+"<br>");
}
%>
<html>
你的sessionID为<%=session.getId()%>
你是第<%=(String)session.getAttribute("count")%>个访问本站的人。
</html>边栏推荐
猜你喜欢

傅里叶变换,拉普拉斯变换学习记录

Pytorch学习记录(七):自定义模型 & Auto-Encoders

Vue项目通过node连接MySQL数据库并实现增删改查操作

Cloud server deployment web project
![[Mini Program Project Development--Jingdong Mall] Custom Search Component of uni-app (Middle)--Search Suggestions](/img/ea/ee1ad50a497478b9d080bb5e4bdfb5.png)
[Mini Program Project Development--Jingdong Mall] Custom Search Component of uni-app (Middle)--Search Suggestions
![[Yellow ah code] Introduction to MySQL - 3. I use select, the boss directly drives me to take the train home, and I still buy a station ticket](/img/7b/f50c5f4b16a376273ba8cd27543676.png)
[Yellow ah code] Introduction to MySQL - 3. I use select, the boss directly drives me to take the train home, and I still buy a station ticket
![[MySQL exercises] Chapter 4 · Explore operators in MySQL with kiko](/img/11/66b4908ed8f253d599942f35bde96a.png)
[MySQL exercises] Chapter 4 · Explore operators in MySQL with kiko

【Unity】编辑器扩展-01-拓展Project视图

google搜索技巧——程序员推荐

动态顺序表的增删查改(C语言实现)
随机推荐
MySQL 日期时间类型精确到毫秒
傅里叶变换,拉普拉斯变换学习记录
射频电路学习之滤波电路
Failure scenarios of @Transactional annotations
Linux安装mysql
2019 NeurIPS | Graph Convolutional Policy Network for Goal-Directed Molecular Graph Generation
[MySQL exercises] Chapter 4 · Explore operators in MySQL with kiko
【小程序项目开发--京东商城】uni-app之自定义搜索组件(上)-- 组件UI
A brief introduction to the SSM framework
【小程序项目开发-- 京东商城】uni-app之商品列表页面 (上)
编译器R8问题Multidex
[Cloud native and 5G] Microservices support 5G core network
MySQL 5.7 安装教程(全步骤、保姆级教程)
2022 Hangzhou Electric Cup Super League 3
Modular specifications
【云原生】微服务之Feign的介绍与使用
sqli-labs(less-11)
7/28-7/29 Expectation + thinking + suffix array + ST table
我的创作纪念日
【问题记录】TypeError: eval() arg 1 must be a string, bytes or code object