全局应用程序对象application
- 不同用户的sesion对象互不相同,但有时候用户之间可能需要一个
共享对象
,当Web服务器对象启动后就产生了这样一个唯一的内置对象application。 - 任何用户在访问同一Web服务目录的各个页面时,共享一个application对象,直到服务器关闭,这个application对象被取消为止。
- application对象也可以进行数据的存储。
- application对象在整个应用区域中都有效,而session只是在当前客户的会话范围内有效,当超过保存时间则被收回。
application访问应用程序初始化参数
- application对象提供了对应用程序初始化参数进行访问的方法。
- 应用程序初始化参数在web.xml文件中进行设置,web.xml文件位于Web应用所在目录下的WEB-INF子目录中。在web.xml文件中通过表级配置应用程序初始化参数。(
???
)
管理应用程序环境属性
- 获得application 对象的所有属性名称的
枚举对象
:
public Enumeration getAttributeNames()
- 从application对象中获取指定对象名
public Object getAttribute(String key)
- 存储数据对象:
public void setAttribute(String key , Object obj)
- 从application对象中去掉指定名称的属性
public void removeAttribute(String key , Object obj)
application对象方法全家桶
Object getAttribute(String name):返回给定名的属性值。
Enumeration getAttributeNames():返回所有可用属性名的枚举。
void setAttribute(String name,Object obj):设定属性的属性值。
void removeAttribute(String name) :删除一属性及其属性值。
String getServerInfo():返回JSP(SERVLET)引擎名及版本号。
String getRealPath(String path) :返回一虚拟路径的真实路径。
ServletContext getContext(String uripath) :返回指定WebApplication的application对象。
int getMajorVersion():返回服务器支持的Servlet API的最大版本号。
int getMinorVersion():返回服务器支持的Servlet API的最大版本号。
String getMimeType(String file):返回指定文件的MIME类型。
URL getResource(String path):返回指定资源(文件及目录)的URL路径。
InputStream getResourceAsStream(String path):返回指定资源的输入流。
RequestDispatcher getRequestDispatcher(String uripath):返回指定资源RequestDispatcher对象。
Servlet getServlet(String name):返回指定名的Servlet。
Enumeration getServlets():返回所有Servlet的枚举。
Enumeration getServletNames():返回所有Servlet名的枚举。
void log(String msg):把指定消息写入Servlet的日志文件。
void log(Exception exception,String msg):把指定异常的栈轨迹和错误消息写入Servlet的日志文件。
void log(String msg,Throwable throwable):把栈轨迹和给出的Throwable异常的说明信息写入到Servlet
的日志文件。
留以记录,明天再解决。
- sendMessage()怎么用
https://blog.csdn.net/qq_29656961/article/details/78125164
//