ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

JSP-九大内置对象

2021-01-18 23:05:05  阅读:196  来源: 互联网

标签:内置 String abstract pageContext 九大 JSP void public name


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

标签:内置,String,abstract,pageContext,九大,JSP,void,public,name
来源: https://www.cnblogs.com/shenleg/p/14258981.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有