JSP一共有四个内置对象:page、request、ssession、application
ps:cookie不属于内置对象
这四个内置对象都有setAttribute、getAttribute方法,都能作为传输数据的载体
page的作用域对应的内置对象是pageContext。
request的作用域对应的内置对象是request。
session的作用域对应的内置对象是session。
application的作用域对应的内置对象是application。
作用域的范围
page: 只在当前页面有效
request: 在一次请求内有效
session: 在一次会话内有效
application: 对应整个WEB应用
通过一个实例:网站访问量统计来演示作用域
Integer count = (Integer) application.getAttribute("count");
if(count == null){
count = 1;
application.setAttribute("count",count);
}else{
count++;
application.setAttribute("count",count);
}
您是第<%=count%>位访客
application记录整个WEB应用,从不同浏览器访问也能记录,前提是不关闭tomcat。