JAVA-JSP內置對象之page範圍
阿新 • • 發佈:2017-09-24
style ext ttr col attribute 資料 方法 當前 htm
相關資料:
《21天學通Java Web開發》
page範圍
1.當前頁有效。
2.通過使用pageContext的aetAttribute()設置屬性,並通過pageContext的getAttribute()方法來取得屬性。
pagedemo.jsp
1 <%@ page language="java" contentType="text/html;charset=gb2312" %>
2 <html>
3 <head>
4 <title>page範圍</title>
5 </head>
6 <body>
7 <%-- 在page範圍設置屬性--%>
8 <%
9 pageContext.setAttribute("name","James");//設置屬性name,其值為James
10 %>
11 <%--取得page範圍屬性--%>
12 <%
13 String strName = (String)pageContext.getAttribute("name");//取值屬性name的值
14 out.println("page範圍:name屬性值為" + strName);//輸出字符串strName的值
15 %>
16 </body>
17 </html>
View Code
pagedemo2.jsp
1 <%@ page language="java" contentType="text/html;charset=gb2312" %>
2 <html>
3 <head>
4 <title>page範圍</title>
5 </head>
6 <body>
7 <% --取得page範圍屬性--%>
8 <%
9 String strName = (String)pageContext.getAttribute("name");//取值屬性name的值
10 out.println("page範圍:name屬性值為" + strName);//輸出字符串strName的值
11 %>
12 </body>
13 </html>
View Code
JAVA-JSP內置對象之page範圍