Jsp application对象(全局变量)

常用方法:

<%@ page import="java.util.Enumeration" %><%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2020/2/13
  Time: 21:19
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>application对象</title>
</head>
<body>
    <p>application内置对象</p>
    <hr>
    <%
        application.setAttribute("city", "太原");
        application.setAttribute("postcode", "1000");
        application.setAttribute("email", "1234@163.com");
    %>
    所在城市是:<%=application.getAttribute("city")%><br>
    application中的属性有:<%
        Enumeration attributes = application.getAttributeNames();   //枚举
        while (attributes.hasMoreElements()){
            out.println(attributes.nextElement()+"&nbsp;&nbsp");
        }
    %><br>
    jsp(servlet)引擎名及版本号:<%=application.getServerInfo()%><br>

</body>
</html>
View Code

结果:

原文地址:https://www.cnblogs.com/CPU-Easy/p/12305371.html