javaweb学习18:JSP内置对象及作用域
-
JSP:9大内置对象
-
PageContext:存东西
-
Request:存东西
-
Response
-
Session:存东西
-
Application:【ServletContext】:存东西
-
config:【ServletConfig】
-
out
-
page:几乎不用
-
Exception:跟Java异常一样;
-
-
使用场景:
-
Request:客户端向服务器发送请求,产生的数据,用户看完就没用了,比如:新闻;
-
Session:客户端向服务器发送请求,产生的数据,用户用完一会还有用,比如:购物车;Hystrix
-
Application:
-
-
总结:
-
参数的作用域范围:参考:Java双亲委派机制;
-
JVM:双亲委派机制;
-
-
分析代码:pageContext.setAttribute( );
//PageContext类:
public static final int PAGE_SCOPE = 1;
public static final int REQUEST_SCOPE = 2;
public static final int SESSION_SCOPE = 3;
public static final int APPLICATION_SCOPE = 4;
//setAttribute源码
public void setAttribute(String name, Object attribute, int scope) {
switch(scope) {
case 1:
this.mPage.put(name, attribute);
break;
case 2:
this.mRequest.put(name, attribute);
break;
case 3:
this.mSession.put(name, attribute);
break;
case 4:
this.mApp.put(name, attribute);
break;
default:
throw new IllegalArgumentException("Bad scope " + scope);
}
}
-
代码案例:重要
<%
-
代码案例2:分析作用域底层
<%
-
代码案例:页面跳转
<%
分类:
06-Java Web
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律