pageScope对象
来源:1-5 EL的作用域对象
五福男孩
2019-07-07 12:03:56
pageScope对象如何使用?请老师写个简单的例子
1回答
好帮手慕柯南
2019-07-07
同学你好!使用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>
如果我的回答解决了你的疑惑,请采纳,祝学习愉快~
相似问题