jsp的9个内置对象

jsp的9个内置对象
指在JSP的<%=%> 和<% %>中可以直接使用的对象
这里写图片描述



pageContext(重要)
1、本身也是一个域对象:它可以操作其它三个域对象(request session application)的数据
void setAttribute(String name,Object o);
Object getAttribute(String name);
void removeAttribute(String name);
操作其它域对象的方法
void setAttribute(String name,Object o,int Scope);
Object getAttribute(String name,int Scope);
void removeAttribute(String name,int Scope);
scpoe的值:
PageContext.PAGE_SCOPE
PageContext.REQUEST_SCOPE
PageContext.SESSION_SCOPE
PageContext.APPLICATION_SCOPE

<% 
       //pageContext.setAttribute("like", "page");
       pageContext.setAttribute("like", "page",PageContext.PAGE_SCOPE);

       //request.setAttribute("like", "request");
       pageContext.setAttribute("like", "request",PageContext.REQUEST_SCOPE);

       //session.setAttribute("like", "session");
       pageContext.setAttribute("like", "session",PageContext.SESSION_SCOPE);

       //application.setAttribute("like", "application");
       pageContext.setAttribute("like", "application",PageContext.APPLICATION_SCOPE);

       request.getRequestDispatcher("/t5.jsp").forward(request, response);
       //response.sendRedirect(request.getContextPath()+"/t5.jsp");

       //pageContext.forward("/t5.jsp");
       //pageContext.include("/t2.jsp");
    %>

findAttribute(String name); 自动从page request session application依次查找,找到了就取值,结束查找。

<!-- findAttribute自动从page request session application依次查找 
    -->
    <%=pageContext.findAttribute("like") %>

2、它可以创建其它的8个隐式对象
在普通类中可以通过PageContext获取其他JSP隐式对象。自定义标签时就使用。

3、提供了的简易方法
pageContext.forward(“2.jsp”);
pageContext.include(“2.jsp”);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值