7. jsp内建对象之application

第七讲 jsp内建对象之application

服务器启动,产生application对象,为用户分配application对象。
不同客户产生同一个application对象;
所有客户的application对象都是同一个。
例如:聊天室程序、计数器程序、留言板程序。
生命周期:服务器的启动至关闭。
主要方法:
1 Object getAttribute(String name) 返回给定名的属性值
2 Enumeration getAttributeNames() 返回所有可用属性名的枚举
3 void setAttribute(String name,Object obj) 设定属性的属性值
4 void removeAttribute(String name) 删除一属性及其属性值
5 String getServerInfo() 返回JSP(SERVLET)引擎名及版本号
6 String getRealPath(String path) 返回一虚拟路径的真实路径
7 ServletContext getContext(String uripath) 返回指定WebApplication的application对象
8 int getMajorVersion() 返回服务器支持的Servlet API的最大版本号
9 int getMinorVersion() 返回服务器支持的Servlet API的最大版本号
10 String getMimeType(String file) 返回指定文件的MIME类型
11 URL getResource(String path) 返回指定资源(文件及目录)的URL路径
12 InputStream getResourceAsStream(String path) 返回指定资源的输入流
13 RequestDispatcher getRequestDispatcher(String uripath) 返回指定资源的RequestDispatcher对象
14 Servlet getServlet(String name) 返回指定名的Servlet
15 Enumeration getServlets() 返回所有Servlet的枚举
16 Enumeration getServletNames() 返回所有Servlet名的枚举
17 void log(String msg) 把指定消息写入Servlet的日志文件
18 void log(Exception exception,String msg) 把指定异常的栈轨迹及错误消息写入Servlet的日志文件
19 void log(String msg,Throwable throwable) 把栈轨迹及给出的Throwable异常的说明信息 写入Servlet的日志文件
常用的方法为getAttribute、setAttribute。

猜你喜欢

转载自zhiyongliu.iteye.com/blog/1684459