ServletContext保存访问量

ServletContext application  = this.getServletContext(); 

       Integer count = (Integer)application.getAttribute("count");

       if(count == null) {

           count = 1;

       } else {

           count++;

       }

       response.setContentType("text/html;charset=utf-8");

       response.getWriter().print("<h1>本页面一共被访问" + count + "次!</h1>");

       application.setAttribute("count", count);

posted @ 2015-10-13 19:37  任重而道远  阅读(219)  评论(0编辑  收藏  举报