zoukankan      html  css  js  c++  java
  • JSP-九大内置对象

    pageContext

    常用方法

    PageContext

    abstract public HttpSession getSession();
    
    abstract public Object getPage();
    
    abstract public ServletRequest getRequest();
    
    abstract public ServletResponse getResponse();
    
    abstract public Exception getException();
    
    abstract public ServletConfig getServletConfig();
    
    abstract public ServletContext getServletContext();
    
    abstract public void forward(String relativeUrlPath) throws ServletException, IOException;
    
    abstract public void include(String relativeUrlPath) throws ServletException, IOException;
    
    abstract public void include(String relativeUrlPath, boolean flush) throws ServletException, IOException;
    
    abstract public void handlePageException(Exception e) throws ServletException, IOException;
    
    public BodyContent pushBody() {}
    
    public ErrorData getErrorData() {...}
    

    JspContext

    abstract public Object getAttribute(String name); // 返回与页面范围中的名称关联的对象;如果未找到,则返回null
    
    abstract public Object getAttribute(String name, int scope);
    
    abstract public void setAttribute(String name, Object value);
    
    abstract public void setAttribute(String name, Object value, int scope);
    
    abstract public Object findAttribute(String name); // 在页面,请求,会话(如果有效)和应用程序范围内按顺序搜索命名属性,并返回关联的值或null
    
    abstract public void removeAttribute(String name);
    
    abstract public void removeAttribute(String name, int scope);
    
    abstract public int getAttributesScope(String name);
    
    abstract public JspWriter getOut();
    
    public abstract ELContext getELContext();
    
    public JspWriter pushBody( java.io.Writer writer ) {}
    
    public JspWriter popBody() {}
    

    session

    application

    config

    out

    page

    request

    response

    exception

    存数据

    <body>
    <%
        pageContext.setAttribute("name1", "value1");
        request.setAttribute("name2", "value2");
        session.setAttribute("name3", "value3");
        application.setAttribute("name4", "value4");
        application.setAttribute("name1", "value11");
    %>
    <%
        // 从底层到高层寻找,优先用底层同名值
        String name1 = (String) application.getAttribute("name1");
        String name2 = (String) application.getAttribute("name2");
        String name3 = (String) application.getAttribute("name3");
        String name4 = (String) application.getAttribute("name4");
        String name5 = (String) application.getAttribute("name5");
    %>
    <h1>${name1} + ${pageContext.getAttributesScope("name1")}</h1>
    <h1>${name2} + ${pageContext.getAttributesScope("name2")}</h1>
    <h1>${name3} + ${pageContext.getAttributesScope("name3")}</h1>
    <h1>${name4} + ${pageContext.getAttributesScope("name4")}</h1>
    <h1>${name5} + ${pageContext.getAttributesScope("name5")}</h1>
    <%=name5%> <%--没有值是会显示null--%>
    <h1>${pageScope.get("name1")}</h1>
    <h1>${applicationScope.get("name1")}</h1> <%--优先用本作用域里的值--%>
    </body>
    

    一个是直接获取,一个从pageContext里拿:

  • 相关阅读:
    node-webkit 不支持html5_video播放mp4的解决方法
    node-webkit(Windows系统) 打包成exe文件后,被360杀毒软件误报木马的解决方法
    剑指 Offer 36. 二叉搜索树与双向链表
    剑指 Offer 33. 二叉搜索树的后序遍历序列
    Leetcode96. 不同的二叉搜索树
    Leetcode95. 不同的二叉搜索树 II
    leetcode1493. 删掉一个元素以后全为 1 的最长子数组
    Leetcode1052. 爱生气的书店老板
    Leetcode92. 反转链表 II
    Leetcode495. 提莫攻击
  • 原文地址:https://www.cnblogs.com/shenleg/p/14258981.html
Copyright © 2011-2022 走看看