zoukankan      html  css  js  c++  java
  • 10.application对象

     1.application对象实现了用户数据的共享,可存放全局变量

     2.application开始于服务器的启动,终止于服务器的关闭。

    3.在用户的前后连接或不同用户之间的连接中,可以对application对象的同一属性进行操做。

    4.在任何地方对application对象属性的操作,都将影响到其他用户对此的访问。

    5.服务器的启动和关闭决定了application对象的生命。

    6.application对象是ServletContext类的实例。

    application对象

    1.public void setAttribute(String name,Object value)使用指定名称将对象绑定到此会话。

    2.public Object getAttribute(String name)返回与此回话中指定名称绑定在一起的对象,如果没有对象绑定在改名称下,则返回null

    3.Enumeration getAttributeNames()返回所有可用属性名的枚举。

    4.String getServInfo() 返回JSP(SERVLET)引擎名及版本号

    应用如下:

    <%@ page language="java" import="java.util.*"
        contentType="text/html; charset=utf-8"%>
    <%
        String path = request.getContextPath();
        String basePath = request.getScheme() + "://"
                + request.getServerName() + ":" + request.getServerPort()
                + path + "/";
    %>
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'login.jsp' starting page</title>
    
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
        <link rel="stylesheet" type="text/css" href="styles.css">
        -->
    
    </head>
    
    <body>
        <h1>application内置对象</h1>
        <%
        application.setAttribute("city","北京");
        application.setAttribute("postcode","10000");
        application.setAttribute("email","list@126.com");
         %>
         城市:<%=application.getAttribute("city") %><br>
         application中的属性有:
         <%
         Enumeration attributes = application.getAttributeNames();
         while(attributes.hasMoreElements()){
         out.println(attributes.nextElement()+"&nbsp;&nbsp");
         }
          %><br>
          JSP(SERVLET)引擎名以及版本号:<%=application.getServerInfo() %>
    </body>
    </html>

    运行:

    可以看到application里面已经添加了我们设置的一些属性

  • 相关阅读:
    linux下的进程
    进程间通讯
    const关键字
    关于嵌入式web服务器
    指针
    内存管理(malloc和free的用法)
    关于read和fread
    C库的制作
    C语言考试
    docker 配置阿里云镜像加速
  • 原文地址:https://www.cnblogs.com/caimuqing/p/5776421.html
Copyright © 2011-2022 走看看