@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
/*
* 1,创建ServletContext
* 2,从ServldtCcontext中获取名为 cont的属性
*
*/
ServletContext app = this.getServletContext();
Integer cont = (Integer)app.getAttribute("cishuo");
if(cont == null) {
cont = 1;
app.setAttribute("cishuo", cont);
}else {
app.setAttribute("cishuo", cont+1);
}
PrintWriter pw = resp.getWriter();
pw.print(cont);
}
ServletContext 统计访问次数
最新推荐文章于 2021-11-04 22:46:51 发布