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里拿:

  • 相关阅读:
    判断字符串是否为数字
    Javascript to validate HKID number
    ServiceNow 中Reference 的 dynamic creation script
    Dynamic CRM 中修改实体中主字段的长度
    字符串的压缩与解压
    JDBC中重要的类/接口-Connection、DriverManager、ResultSet、Statement及常用方法
    java读取指定package下的所有class
    mybatis由JDBC的演化过程分析
    Java类与对象初始化的过程(一道经典的面试题)
    StringBuffer和StringBuilder区别?
  • 原文地址:https://www.cnblogs.com/shenleg/p/14258981.html
Copyright © 2011-2022 走看看