pageContext 是 javax.servlet.jsp.PageContext 的实例对象。

pageContext 对象表示整个 JSP 页面,可以获取或删除以下对象的任意属性:
.page
.request
.session
.application

方  法 说  明
Object findAttribute (String AttributeName) 按 page、request、session、application 的顺序查找指定的属性,并返回对应的属性值。如果没有相应的属性,则返回 NULL
Object getAttribute (String AttributeName, int Scope) 在指定范围内获取属性值。与 findAttribute 不同的是,getAttribute 需要指定查找范围
void removeAttribute(String AttributeName, int Scope) 在指定范围内删除某属性
void setAttribute(String AttributeName, Object AttributeValue, int Scope) 在指定范围内设置属性和属性值
Exception getException() 返回当前页的 Exception 对象
ServletRequest getRequest() 返回当前页的 request 对象
ServletResponse getResponse() 返回当前页的 response 对象
ServletConfig getServletConfig() 返回当前页的 ServletConfig 对象
HttpSession getSession() 返回当前页的 session 对象
Object getPage() 返回当前页的 page 对象
ServletContext getServletContext() 返回当前页的 application 对象

示例

修改值:

pageContext.setAttribute("info", "修改page范围的值", 1); pageContext.setAttribute("info", "修改request范围的值", 2); pageContext.setAttribute("info", "修改session范围的值", 3); pageContext.setAttribute("info", "修改application范围的值", 4);

取值(方法一):

pageContext.getRequest().getAttribute("info");//request 设定的值 pageContext.getSession().getAttribute("info");//session 设定的值 pageContext.getServletContext().getAttribute("info");application 设的值

取值(方法二):

pageContext.getAttribute("info", 1);//page)内的值 pageContext.getAttribute("info", 2);//request)内的值 pageContext.getAttribute("info", 3);//session)内的值 pageContext.getAttribute("info", 4);//application)内的值