(十四):application属性范围 (JSP学习第三天)
application 属性范围
在整个服务器上保存,所有用户都可以使用,但重启服务器无法得到属性
设置application 属性范围 application_scope_01.jsp
<%@ page language="java" contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import="java.util.*"%>
<html>
<head>
<title>测试</title>
</head>
<body>
<%
application.setAttribute("name","小明");
application.setAttribute("birthday",new Date());
%>
<a href="application_scope_02.jsp">application链接跳转</a>
</body>
</html>
跳转后的页面 application_scope_02.jsp
<%@ page language="java" contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import="java.util.*"%>
<html>
<head>
<title>测试</title>
</head>
<body>
<%
String username=(String)application.getAttribute("name");
Date birthday=(Date)application.getAttribute("birthday");
%>
<h1>姓名:<%=username%></h1>
<h2>出生:<%=birthday%></h2>
</body>
</html>
浙公网安备 33010602011771号