pageContext 针对某一页
request 针对某一请求
session 针对某一会话
application 整个服务,所有用户共享同一数据、对象等等

解决方案 »

  1.   

    多谢楼上指教!
    不过application里setAttribute(),getAttribute()和removeAttribute()是做什么的,我觉得他们应该是针对每个用户的,如果是这样会不会有共享冲突。如同时几个B端在调用setAttribute(),getAttribute()怎么保持数据的一致性。
      

  2.   

    application属性对应ServletContext对象,这个对象是整个Servlet容器的全局变量,所以一般在里面放一些需要被缓存的东西,所有的Servlet,jsp都能得到唯一的ServletContext
      

  3.   

    我也明白是那个对象,他是全局变量,但是我还是不明白他怎么实现数据的一致性。每个webapplication只有一个唯一的application,但是多个用户是可以同时访问它的。
      

  4.   

    至于如何同步就是Servlet容器自己的事了
      

  5.   

    Application对象与Session对象功能比较类似,也是用来保存信息的。实现在不同页面间参数传递。但Application对象是所有用户共享的任何用户都可以访问它。而Session对象则对每一个用户是私有的。所以一般用Application对象业实现同一个网站上多个用户共享信息的功能。
    Application对象的常用方法如下:
    (1)getAttribute(String name) 返回存在于Application对象中的指定名称的变量(或对象)的值,如果不存在此名称的变量(或对象),则返回null.
    (2)getAttributeNames()返回全部存在于Application 对象中的变量(或对象),返回值是一个Enumeration对象的实例。
    (3)getInitParameter(String name)返回 存在于Application对象中指定名称的变量(或对象)的初始值。
    (4)getServerInfo()返回当前使用的servlet编译器的版本。
    (5)setAttribute(String name, Object value)将指定的变量(或对象)的值保存在 Application对象中。
    下面是一个使用Application的例子:
    <%
      int count ;
      count = (Integer) application.getAttribute("basic1.counter");
      if (count == null)
        count = new Integer(0);
      count = new Integer(count.intValue() + 1);
      application.setAttribute("basic1.counter", count);
    %><html>
    <head>
    <title>Counter</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    </head><body bgcolor="#FFFFFF">
    <h1>您是第<%= count %>位参观者!</h1>
    </body>
    </html>