page属性范围表示将一个属性设置在本页上,跳转之后无法取得。
示例:
page_scope_01.jsp
<%@pagecontentType="text/html; charset=utf-8"%>
<%@pageimport = "java.util.*"%>
<html>
<head><title>张龙翔Java高端培训</title></head>
<body>
<%
pageContext.setAttribute("name","李兴华");
pageContext.setAttribute("birthday",new Date());
%>
<%
String username = (String)pageContext.getAttribute("name");
Date userbirthday = (Date)pageContext.getAttribute("birthday");
%>
<h2>姓名:<%=username%></h2>
<h2>生日:<%=userbirthday%></h2>
</body>
</html>
把上例改成:page_scope_02.jsp 转向 page_scope_03.jsp,会发现page范围在跳转后无效。
page_scope_02.jsp
<%@page contentType="text/html; charset=utf-8"%>
<%@page import = "java.util.*"%>
<html>
<head><title>张龙翔Java高端培训</title></head>
<body>
<%
pageContext.setAttribute("name", "李兴华");
pageContext.setAttribute("birthday", new Date());
%>
<jsp:forward page="page_scope_03.jsp"/>
</body>
</html>
page_scope_03.jsp
<%@page contentType="text/html; charset=utf-8"%>
<%@page import = "java.util.*"%>
<html>
<head><title>张龙翔Java高端培训</title></head>
<body>
<%
String username = (String)pageContext.getAttribute("name");
Date userbirthday = (Date)pageContext.getAttribute("birthday");
%>
<h2>姓名: <%=username %></h2>
<h2>生日: <%=userbirthday %></h2>
</body>
</html>