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>
  • 相关阅读:
    开源博客平台WordPress十岁啦!
    (转载)C# Attribute 用法备忘
    hibernate入门
    Hibernate对象关系映射基础
    struts2UI标签
    struts2文件上传2(多文件)
    struts2验证(手工)
    通过修改注册表改变txt文件的默认打开方式
    struts2验证(XML)
    Struts国际化
  • 原文地址:https://www.cnblogs.com/diaozhaojian/p/6209136.html
Copyright © 2011-2022 走看看