在IDEA里编写显示当前页面刷新次数代码
代码:
<html>
<body>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
Integer count = (Integer) application.getAttribute("count");
if(count==null){
count=1;
application.setAttribute("count",count);
}else{
count++;
application.setAttribute("count",count);
}
%>
<%= "您刷新第"+count+"次" %>
</body>
</html>
jsp页面的编码 这两个地方需要设置:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page contentType="text/html;charset=utf-8"%>
1.pageEncoding指的是jsp文件本身在本地保存时的编码方式。
2.contentType的charset指的是服务器发送网页内容给客户端时所使用的编码。
application对象:
1.当Web服务器启动时,Web服务器会自动创建一个application对象,application对象一旦创建,他将一直存在,直到Web服务器关闭。
2.application对象的作用范围:application对象是一个应用程序级的对象,它作用于当前Web应用程序,也即作用于当前网站,所有访问当前网站的客户都共享一个application对象。
3. application对象的基类是javax.servlet.ServletContext类。
4. ServletContext类:用于表示应用程序的上下文。
setAttribute\getAttribute方法:
setAttribute("给这个变量取的名字“,变量);
getAttribute(“取得名字”)就得到变量了