JAVA-JSP内置对象之pageContext对象取得不同范围属性

 

相关资料:
《21天学通Java Web开发》

pageContext对象取得不同范围属性

pageContextDemo.jsp

 1 <%@ page language="java" contentType="text/html;charset=gb2312" %>
 2 <html>
 3 <head>
 4   <title>通过pageContext对象取得不同范围的属性</title>
 5 </head>
 6 <body>
 7   <%
 8     pageContext.setAttribute("name","page_James");//设置page范围name属性
 9     request.setAttribute("name","request_James");//设置requset范围name属性
10     session.setAttribute("name","session_James");//设置session范围name属性
11     application.setAttribute("name","application_James");//设置application范围name属性
12   %>
13   <%
14     //获得page范围name属性
15     String pageStr = (String)pageContext.getAttribute("name","pageContext.PAGE_SCOPE");
16     //获得page范围name属性
17     String requestStr = (String)pageContext.getAttribute("name","pageContext.REQUEST_SCOPE");
18     //获得session范围name属性
19     String sessionStr = (String)pageContext.getAttribute("name","pageContext.SESSION_SCOPE");
20     //获得application范围name属性
21     String applicationStr = (String)pageContext.getAttribute("name","pageContext.APPLICATION_SCOPE");
22   %>
23   <%="page范围:name属性值"+pageStr%><br>
24   <%="request范围:name属性值"+requestStr%><br>
25   <%="session范围:name属性值"+sessionStr%><br>
26   <%="application范围:name属性值"+applicationStr%><br>
27 </body>
28 </html>
View Code

 

posted on 2017-10-15 13:13  疯狂delphi  阅读(592)  评论(0编辑  收藏  举报

导航