zoukankan      html  css  js  c++  java
  • 用application实现一个网页的浏览计数器

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    <%
    Object count = application.getAttribute("count") ;
    
    if(count==null)//首先判断是否存在该全局变量
    {
        //创建全局属性
        application.setAttribute("count",1) ;
    }
    else
    {
        int co = Integer.parseInt(count.toString()) ; //定义变量并赋值
        
        out.print(co++) ;
        
        //写会
        application.setAttribute("count", co) ;
    }
    %>
    <a href="application2.jsp" >访问</a>
    </body>
    </html>
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    <%
    
    //获取application属性
    int count = Integer.parseInt(application.getAttribute("count").toString()) ;
    
    out.print("网站计数器:"+count++) ;
    application.setAttribute("count", count) ;
    %>
    </body>
    </html>
  • 相关阅读:
    安装mysql apache php smb
    解决IE8placeholder属性问题
    将博客搬至CSDN
    shell脚本获取配置文件中的内容
    shell sed指令全解
    salt一键部署hive
    salt一键部署habse
    salt一键部署kafka
    salt一键部署elasticsearch
    salt一键部署mysql
  • 原文地址:https://www.cnblogs.com/diaozhaojian/p/6209136.html
Copyright © 2011-2022 走看看