• 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 = Integer.parseInt(application.getAttribute("count").toString()) ;
    
    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>
  • 相关阅读:
    (转)Apache与Tomcat 区别联系
    (转)JAVA排序汇总
    (转)Java线程:大总结
    (转)Java线程:新特征-原子量,障碍器
    (转)Java线程:新特征-条件变量
    oracle中的not in和not exists注意事项
    oracle字符乱码的解决方法
    线刷和卡刷的区别
    nexus5刷机
    linux上复制行到另一个文件
  • 原文地址:https://www.cnblogs.com/20gg-com/p/6039973.html
Copyright © 2020-2023  润新知