那位高人可以给详细介绍一下JSP内部对象application到底是做什么的? pageContext 针对某一页request 针对某一请求session 针对某一会话application 整个服务,所有用户共享同一数据、对象等等 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 多谢楼上指教!不过application里setAttribute(),getAttribute()和removeAttribute()是做什么的,我觉得他们应该是针对每个用户的,如果是这样会不会有共享冲突。如同时几个B端在调用setAttribute(),getAttribute()怎么保持数据的一致性。 application属性对应ServletContext对象,这个对象是整个Servlet容器的全局变量,所以一般在里面放一些需要被缓存的东西,所有的Servlet,jsp都能得到唯一的ServletContext 我也明白是那个对象,他是全局变量,但是我还是不明白他怎么实现数据的一致性。每个webapplication只有一个唯一的application,但是多个用户是可以同时访问它的。 至于如何同步就是Servlet容器自己的事了 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> ext开发的系统,还不错,jacob_liang的系统平台、统一用户 纠结了3,4天的一个问题,尝试过很多方法都没解决。求助!急急急!!! 视频服务器中header头如何设置? SSH 包冲突 javascript安全问题 JBoss不能启动 业界流行且容易上手的开源工作流引擎 Struts 中文乱码问题 以及 URL暴露表单数据和SessionID问题,急~~~ 问在 J2EE1.3 中配置 EJB 的问题 配置j2ee server 请问(面试题):什么是框架?什么时候使用框架?为什么要使用框架?使用框架的优缺点是什么?举例说出你所熟悉的框架。 iBatis查询问题
不过application里setAttribute(),getAttribute()和removeAttribute()是做什么的,我觉得他们应该是针对每个用户的,如果是这样会不会有共享冲突。如同时几个B端在调用setAttribute(),getAttribute()怎么保持数据的一致性。
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>