域对象

1.四个域对象分别为
1)pageContext (PageContextImpl)可以保存数据在同一个 jsp 页面中使用 当前jsp页面有效
2)request(HttpServletRequest) 一次请求有效可以保存数据在同一个 request 对象中使用。经常用于在转发的时候传递数据
3) session(HttpSession) 可以保存在一个会话中使用 (会话:打开浏览器访问对象 直到关闭浏览器)
4)application(ServletContext) 就是 ServletContext 对象 (整个web工程内有效)

2.域对象就是像map一样存取数据的对象 详细可见以前内容
//给域对象设置值
<%
pageContext.setAttribute("key","pageContex");
request.setAttribute("key","requset");
session.setAttribute("key","session");
application.setAttribute("key","app");

%>
//取出值 在同一个页面下都有值
<%=pageContext.getAttribute("key")%> <br/>
<%=request.getAttribute("key")%><br/>
<%=session.getAttribute("key")%><br/>
<%=application.getAttribute("key")%><br/>

//请求转发到另一个页面,此时pageContext是null原因见上面
没消失说明由缓存 其他同理
<%
request.getRequestDispatcher("/scope.jsp").forward(request,response);
%>
3.四个域对象使用的顺序是他们影响范围从小到大的顺序
都是为了服务器不用了最好就释放

 

posted @ 2020-07-24 14:46  why666  阅读(701)  评论(0)    收藏  举报