pageScope对象

pageScope对象

pageScope对象如何使用?请老师写个简单的例子

正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

1回答
好帮手慕柯南 2019-07-07 14:44:43

同学你好!使用pageContext可以访问page、request、session、application范围的变量。具体使用与其他作用域基本相同,同学可以看一下下面的例子:

<%@page contentType="text/html;charset=gb2312"%>

<html><head><title>pageContext对象_例1</title></head>

<body><br>

<%

//使用pageContext设置属性,该属性默认在page范围内

pageContext.setAttribute("name","jason pageContext");

request.setAttribute("name","imooc request");

session.setAttribute("name","imooc seesion");

application.setAttribute("name","imooc application");

%>

page设定的值:<%=pageContext.getAttribute("name")%><br>

request设定的值:<%=pageContext.getRequest().getAttribute("name")%><br>

session设定的值:<%=pageContext.getSession().getAttribute("name")%><br>

application设定的值:<%=pageContext.getServletContext().getAttribute("name")%><br>


范围1内的值:<%=pageContext.getAttribute("name",1)%><br><!--1代表 page -->

范围2内的值:<%=pageContext.getAttribute("name",2)%><br><!--2代表 request -->

范围3内的值:<%=pageContext.getAttribute("name",3)%><br><!--3代表 session -->

范围4内的值:<%=pageContext.getAttribute("name",4)%><br><!--4代表 application -->
</body>
</html>

如果我的回答解决了你的疑惑,请采纳,祝学习愉快~

问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师