内置对象小结

来源:互联网 发布:个人工作日志软件 编辑:程序博客网 时间:2024/06/05 15:26
一、pageContext(request  session  application :直接将以下代码中的pageContext分别替换为request  session  application 即可)
<%@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
 
 
0 0