第3章 JSP数据交互(二)

1.application内置对象
application实现用户之间的数据共享
void setAttribute(String key,Object value) 以key/value的形式保存对象值
Object getAttribute(String key) 通过key获取对象值
String getRealPath(String path) 返回相对路径的真实路径

统计网站访问次数:
<%
//获取当前网站的访问次数
Integer count=(Integer)application.getAttribute("count");
if(count!=null){
count++;
}else{
count=1;
}
application.setAttribute("count", count);
%>
<%
out.print("当前网站访问次数:"+application.getAttribute("count"));

%>




2.作用域
从小到大:page(pageContext)--->request---->session---->application
page对象作用域只在当前页面有效
request作用域是在当前请求内有效
session作用域是在当前会话内有效
application对象的作用域是在应用上下文


3.cookie默认会存放一个session的id值

原文地址:https://www.cnblogs.com/Chencheno/p/11136917.html