JSP对象-application对象

application对象:

  • application对象实现了用户将数据的共享,可存放全局变量
  • application开始于服务器的启动,终止于服务器的关闭
  • 在用户的前后连接或不同用户直接的连接中,可以对application对象的同意属性进行操作
  • 服务器的启动和关闭决定了aplication对象的生命
  • application对象是ServletContext类的实例

常用方法:
在这里插入图片描述

<%@page import="java.util.Enumeration"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
    %>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>application内置对象</title>
</head>
<body>
	<h1>application内置对象</h1>
	<%
		application.setAttribute("city","jincheng");
		application.setAttribute("code","123456");
		application.setAttribute("email","huer0000");
		
	%>
	所在城市:<%=application.getAttribute("city") %>
	application中的属性有:<%
		Enumeration attributes = application.getAttributeNames();
		while(attributes.hasMoreElements()){
			out.println(attributes.nextElement()+"&nbsp;&nbsp;&nbsp;");
		}
	%><br>
	JSP(SERVLET)引擎及版本号:<%=application.getServerInfo() %><br>
</body>
</html>
发布了37 篇原创文章 · 获赞 1 · 访问量 418

猜你喜欢

转载自blog.csdn.net/qq_45444864/article/details/105622171