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:分析作用域底层
<%
-
代码案例:页面跳转
<%

浙公网安备 33010602011771号