<%
Integer counter=(Integer)application.getAttribute("counter");
if(counter==null){//如果该页面第一次被访问,则为空
counter=1;
}else{
counter++;
}
//将变量放入application域,在servlet中它是ServletContext
application.setAttribute("counter",counter);
String realpath=application.getRealPath("/");
%>
<body>
当前页面被访问的次数:<%=counter %><br>
Integer counter=(Integer)application.getAttribute("counter");
if(counter==null){//如果该页面第一次被访问,则为空
counter=1;
}else{
counter++;
}
//将变量放入application域,在servlet中它是ServletContext
application.setAttribute("counter",counter);
String realpath=application.getRealPath("/");
%>
<body>
当前页面被访问的次数:<%=counter %><br>
</body>
----------------------------------------------------------------------------------------------------------------------------------------------------------
而session是一对一的,是一次会话有效
一次会话包含多个请求
request