<%-- 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>