JSP 08: page和pageContent内置对象

1.  page内置对象, 等同于this

在index.jsp中, 运行:

<%
  System.out.println(page == this);
%>

效果:

true

2.  四大域对象:  page  request  session  appliaction

page作用域:     在 当前JSP页面 有效

request作用域:      在 请求/请求转发 里有效

session作用域:   在 整个会话周期 有效 (在会话里的请求访问的都是同一个session)

application作用域: 在 整个Web应用里 有效

page < request < session < appliaction

3.  pageContext

pageContext.getOut();       // 得到了一个JSP Writter, 相当于得到了out对象

pageContext.getRequest();     // 获取请求对象

pageContext.getResponse();        // 获取response对象

pageContext.getServletContext();   // 获取application 

pageContext.getSession();      // 获取httpSession 

pageContext.setAttribute("user","李诞");

pageContext.setAttribute("user","庞博",PageContext.APPLICATION_SCOPE);  // 通过第三个变量, 设置了作用域

例如, 在index.jsp中:

<%
  pageContext.setAttribute("user","庞博",PageContext.SESSION_SCOPE);
  System.out.println(session.getAttribute("user"));
%>

效果:

  输出了庞博

原文地址:https://www.cnblogs.com/JasperZhao/p/13505517.html