一、pageContext(request session application :直接将以下代码中的pageContext分别替换为request session application 即可)
注意:pageContext
pageContext中的setAttribute() 的重载方法之一:public abstract void setAttribute(String name,Object o,int scope);
其中scope表示一个属性的保存范围 范围有4个、如下 :
在setAttribute()中有一些常量:
static int APPLICATION_SCOPE
static int SESSION_SCOPE
static int REQUEST_SCOPE
static int PAGE_SCOPE(默认是PAGE_SCOPE)
所以在pageContext设置属性的时候
pageContext.setAttribute("name","某某某",PageContext.REQUEST_SCOPE); 就像当与request
<%@page contentType = "text/html;charset = gbk" %>
<%@page import = "java.util.*" %>
<%
pageContext.setAttribute("name","某某某");
pageContext.setAttribute("date",new Date());
%>
<%
String name = (String)pageContext.getAttribute("name");
Date date = (Date)pageContext.getAttribute("date");
%>
<h2>姓名:<%=name %></h2>
<h2>日期:<%=date %></h2>
注意:pageContext
pageContext中的setAttribute() 的重载方法之一:public abstract void setAttribute(String name,Object o,int scope);
其中scope表示一个属性的保存范围 范围有4个、如下 :
在setAttribute()中有一些常量:
static int APPLICATION_SCOPE
static int SESSION_SCOPE
static int REQUEST_SCOPE
static int PAGE_SCOPE(默认是PAGE_SCOPE)
所以在pageContext设置属性的时候
pageContext.setAttribute("name","某某某",PageContext.REQUEST_SCOPE); 就像当与request