基础知识:详细了解JSP中九个隐含对象
来源:优易学  2011-9-30 12:32:27   【优易学:中国教育考试门户网】   资料下载   IT书店

  七、application对象
  
application对象最常被使用在存取环境的信息。
  因为环境的信息通常都储存在ServletContext中,所以常利用application对象来存取ServletContext中的信息。
  application 对象实现javax.servlet.ServletContext 接口,ServletContext接口容器所提供的方法
  int getMajorVersion( )取得Container主要的Servlet API版本
  int getMinorVersion( )取得Container次要的Servlet API 版本
  String getServerInfo( )取得Container的名称和版本
  String getMimeType(String file)取得指定文件的MIME 类型
  ServletContext getContext(String uripath)取得指定Local URL的Application context
  String getRealPath(String path)取得本地端path的绝对路径
  void log(String message)将信息写入log文件中
  void log(String message, Throwable throwable)将stack trace 所产生的异常信息写入log文件中
  八、pageContext对象
  
pageContext对象能够存取其他隐含对象。
  1.pageContext对象存取其他隐含对象属性的方法,此时需要指定范围的参数。
  
Object getAttribute(String name, int scope)
  Enumeration getAttributeNamesInScope(int scope)
  void removeAttribute(String name, int scope)
  void setAttribute(String name, Object value, int scope)
  范围参数有四个,分别代表四种范围:PAGE_SCOPE、REQUEST_SCOPE、SESSION_SCOPE、APPLICATION_SCOPE
  2.PageContext对象取得其他隐含对象的方法
  
Exception getException( )回传目前网页的异常,不过此网页要为error page,
  JspWriter getOut( )回传目前网页的输出流,例如:out
  Object getPage( )回传目前网页的Servlet 实体(instance),例如:page
  ServletRequest getRequest( )回传目前网页的请求,例如:request
  ServletResponse getResponse( )回传目前网页的响应,例如:response
  ServletConfig getServletConfig( )回传目前此网页的ServletConfig 对象,例如:config
  ServletContext getServletContext( ) 回传目前此网页的执行环境(context),例如:application
  HttpSession getSession( )回传和目前网页有联系的会话(session),例如:session
  3.PageContext对象提供取得属性的方法
  
Object getAttribute(String name, int scope)回传name 属性,范围为scope的属性对象,回传类型为Object
  Enumeration getAttributeNamesInScope(int scope)回传所有属性范围为scope 的属性名称,回传类型为Enumeration
  int getAttributesScope(String name)回传属性名称为name 的属性范围
  void removeAttribute(String name)移除属性名称为name 的属性对象
  void removeAttribute(String name, int scope)移除属性名称为name,范围为scope 的属性对象
  void setAttribute(String name, Object value, int scope)指定属性对象的名称为name、值为value、范围为scope
  Object findAttribute(String name)寻找在所有范围中属性名称为name 的属性对象
  九、exception对象
  
若要使用exception 对象时,必须在page 指令中设定。才能使用。
  exception提供的三个方法:
  getMessage( )
  getLocalizedMessage( )、
  printStackTrace(new java.io.PrintWriter(out))

上一页  [1] [2] [3] 

责任编辑:小草

文章搜索:
 相关文章
热点资讯
资讯快报
热门课程培训