Cookie(页面访问次数)

  1. <%@ page language="java" contentType="text/html; charset=UTF-8"  
  2.     pageEncoding="UTF-8"%>  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">  
  4. <html>  
  5. <head>  
  6. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
  7. <title>页面访问计数器</title>  
  8. </head>  
  9. <body>  
  10. <%  
  11.    Object obj=application.getAttribute("counter");  
  12.    if(obj==null){  
  13.        application.setAttribute("counter",new Integer(1));  
  14.        out.println("该页面被访问1次!<br />");  
  15.    }else{  
  16.        int counterValue=Integer.parseInt(obj.toString());  
  17.        counterValue++;  
  18.        out.println("该页面被访问"+counterValue+"次!<br />");  
  19.        application.setAttribute("counter", counterValue);  
  20.    }  
  21. %>  
  22.   
  23. </body>  
  24. </html> 
posted @ 2017-12-27 11:13  半吊子丶程序员  阅读(514)  评论(0)    收藏  举报