吴裕雄--天生自然JAVA开发JSP-Servlet学习笔记:让多个JSP、Servelet共享数据

<%-- 
    Document   : put-application
    Created on : 2020-4-11, 19:51:55
    Author     : Administrator
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <title>application测试</title>
        <meta name="website" content="http://www.crazyit.org" />
    </head>
    <body>
        <!-- JSP声明 -->
        <%!
            int i=0;
        %>
        <!-- 将i值自加后放入application的变量内 -->
        <%
            application.setAttribute("counter", String.valueOf(++i));
        %>
        <!-- 输出i值 -->
        <%=i%>
    </body>
</html>

<%-- 
    Document   : get-Application
    Created on : 2020-4-11, 19:56:18
    Author     : Administrator
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <title>application测试</title>
        <meta name="website" content="http://www.crazyit.org" />
    </head>
    <body>
        <!-- 直接输出application 变量值 -->
        <%=application.getAttribute("counter")%>
    </body>
</html>

原文地址:https://www.cnblogs.com/tszr/p/12681871.html