整理一下JSP的九大内置对象和四大作用域 (2)

五、page对象:page对象就是指向当前JSP页面本身,有点象类中的this指针,它是java.lang.Object类的实例 。“page” 对象代表了正在运行的由JSP文件产生的类对象,不建议一般读者使用。 作用域    page

常用方法:

1 class getClass 返回此Object的类 

  2 int hashCode() 返回此Object的hash码 

  3 boolean equals(Object obj) 判断此Object是否与指定的Object对象相等 

  4 void copy(Object obj) 把此Object拷贝到指定的Object对象中 

  5 Object clone() 克隆此Object对象 

  6 String toString() 把此Object对象转换成String类的对象 

  7 void notify() 唤醒一个等待的线程 

  8 void notifyAll() 唤醒所有等待的线程 

  9 void wait(int timeout) 使一个线程处于等待直到timeout结束或被唤醒 

  10 void wait() 使一个线程处于等待直到被唤醒 

  11 void enterMonitor() 对Object加锁 

  12 void exitMonitor() 对Object开锁

六、application对象:实现了用户间数据的共享,可存放全局变量。它开始于服务器的启动,直到服务器的关闭,在此期间,此对象将一直存在;这样在用户的前后连接或不同用户之间的连接中,可以对此对象的同一属性进行操作;在任何地方对此对象属性的操作,都将影响到其他用户对此的访问。服务器的启动和关闭决定了application对象的生命。它是ServletContext类的实例。作用域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的日志文件 

七、pageContext对象提供了对JSP页面内所有的对象及名字空间的访问,也就是说他可以访问到本页所在的SESSION,也可以取本页面所在的application的某一属性值,他相当于页面中所有功能的集大成者,它的本类名也叫pageContext。用域    Pageconfig对象

常用方法:

1 JspWriter getOut() 返回当前客户端响应被使用的JspWriter流(out) 

  2 HttpSession getSession() 返回当前页中的HttpSession对象(session) 

  3 Object getPage() 返回当前页的Object对象(page) 

  4 ServletRequest getRequest() 返回当前页的ServletRequest对象(request) 

  5 ServletResponse getResponse() 返回当前页的ServletResponse对象(response) 

  6 Exception getException() 返回当前页的Exception对象(exception) 

  7 ServletConfig getServletConfig() 返回当前页的ServletConfig对象(config) 

  8 ServletContext getServletContext() 返回当前页的ServletContext对象(application) 

  9 void setAttribute(String name,Object attribute) 设置属性及属性值 

  10 void setAttribute(String name,Object obj,int scope) 在指定范围内设置属性及属性值 

  11 public Object getAttribute(String name) 取属性的值 

  12 Object getAttribute(String name,int scope) 在指定范围内取属性的值 

  13 public Object findAttribute(String name) 寻找一属性,返回起属性值或NULL 

  14 void removeAttribute(String name) 删除某属性 

  15 void removeAttribute(String name,int scope) 在指定范围删除某属性 

  16 int getAttributeScope(String name) 返回某属性的作用范围 

  17 Enumeration getAttributeNamesInScope(int scope) 返回指定范围内可用的属性名枚举 

  18 void release() 释放pageContext所占用的资源 

  19 void forward(String relativeUrlPath) 使当前页面重导到另一页面 

  20 void include(String relativeUrlPath) 在当前位置包含另一文件 

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zwdyyw.html