JSP内置对象详解2

⑤ pageContext - javax.servlet.jsp.PageContext
     pageContext对象存储本JSP页面相关信息,如属性、内建对象等。

方法:
1. void setAttribute( String name, Object value, int scope ) ;
     void setAttribute( String name, Object value ) ;
     在指定的共享范围内设置属性。

2. Object getAttribute( String name, int scope ) ;
     Object getAttribute( String name ) ;
     取得指定共享范围内以name为名字的属性值。

3. Object findAttribute( String name ) ;
     按页面、请求、会话和应用程序共享范围搜索已命名的属性。

4. void removeAttribute( String name, int scope ) ;
     void removeAttribute( String name ) ;
     移除指定名称和共享范围的属性。

5. void forward( String url ) ;
     将页面导航到指定的URL。

6. Enumeration getAttributeNamesScope( int scope ) ;
     取得指定共享范围内的所有属性名称的集合。

7. int getAttributeScope( String name ) ;
     取得指定属性的共享范围。

8. ErrorData getErrorDate() ;
     取得页面的errorData对象。

9. Exception getException() ;
     取得页面的exception对象。

10. ExpressionEvaluator getExpressionEvaluator() ;
      取得页面的expressionEvaluator对象。

11. JspWriter getOut() ;
      取得页面的out对象。

12. Object getPage() ;
      取得页面的page对象。

13. ServletRequest getRequest() ;
      取得页面的request对象。

14. ServletResponse getResponse() ;
      取得页面的response对象。

15. ServletConfig getConfig() ;
      取得页面的config对象。

16. ServletContext getServletContext() ;
      取得页面的servletContext对象。

17. HttpSession getSession() ;
      取得页面的session对象。

18. VariableResolver getVariableResolver() ;
      取得页面的variableResolver对象。

19. void include( String url, boolean flush ) ;
      void include( String url ) ;
      包含其他的资源,并指定是否自动刷新。

20. void release() ;
      重置pageContext内部状态,释放所有内部引用。

21. void initialize( Servlet servlet, ServletRequest request, ServletResponse response,
                       String errorPageURL, boolean needSession, int bufferSize, boolean autoFlush ) ;
      初始化未经初始化的pageContext对象。

22. BodyContext pushBody() ;
      BodyContext pushBody( Writer writer ) ;
      保存当前的out对象,并更新pageContext中page范围内的out对象。

23. JspWrite popBody() ;
      取出由pushBody()方法保存的out对象。

24. void handlePageException( Exception e ) ;
      void handlePageException( Thrwoable t ) ;
    

成员:
int PAGE_SCOPE = 1          - 页面共享范围
int REQUEST_SCOPE = 2       - 请求共享范围
int SESSION_SCOPE = 3       - 会话共享范围
int APPLICATION_SCOPE = 4 - 应用程序共享范围
String PAGE = "javax.servlet.jsp.jspPage"
String PAGECONTEXT = "javax.servlet.jsp.jspPageContext"
String REQUEST = "javax.servlet.jsp.jspRequest"
String RESPONSE = "javax.servlet.jsp.jspResponse"
String CONFIG = "javax.servlet.jsp.jspConfig"
String SESSION = "javax.servlet.jsp.jspSession"
String OUT = "javax.servlet.jsp.jspOut"
String APPLICATION = "javax.servlet.jsp.jspApplication"
String EXCEPTION = "javax.servlet.jsp.jspException"


⑥ application - javax.servlet.ServletContext
     application主要功用在于取得或更改Servlet的设定。

方法:
1. Object getAttribute( String name ) ;
     返回由name指定的application属性。

2. Enumeration getAttributes() ;
     返回所有的application属性。

3. ServletContext getContext( String uripath ) ;
     取得当前应用的ServletContext对象。

4. String getInitParameter( String name ) ;
     返回由name指定的application属性的初始值。

5. Enumeration getInitParameters() ;
     返回所有的application属性的初始值的集合。

6. int getMajorVersion() ;
     返回servlet容器支持的Servlet API的版本号。

7. String getMimeType( String file ) ;
     返回指定文件的类型,未知类型返回null。一般为"text/html"和"image/gif"。

8. int getMinorVersion() ;
     返回servlet容器支持的Servlet API的副版本号。

9. String getRealPath( String path ) ;
     返回给定虚拟路径所对应物理路径。

10. RequestDispatcher getNamedDispatcher( String name ) ;
      为指定名字的Servlet对象返回一个RequestDispatcher对象的实例。

11. RequestDispatcher getRequestDispatcher( String path ) ;
      返回一个RequestDispatcher对象的实例。

12. URL getResource( String path ) ;
      返回指定的资源路径对应的一个URL对象实例,参数要以"/"开头。

13. InputStream getResourceAsStream( String path ) ;
      返回一个由path指定位置的资源的InputStream对象实例。

14. Set getResourcePaths( String path ) ;
      返回存储在web-app中所有资源路径的集合。

15. String getServerInfo() ;
      取得应用服务器版本信息。

16. Servlet getServlet( String name ) ;
      在ServletContext中检索指定名称的servlet。

17. Enumeration getServlets() ;
      返回ServletContext中所有servlet的集合。

18. String getServletContextName() ;
      返回本web应用的名称。

19. Enumeration getServletContextNames() ;
      返回ServletContext中所有servlet的名称集合。

20. void log( Exception ex, String msg ) ;
      void log( String msg, Throwable t ) ;
      void log( String msg ) ;
      把指定的信息写入servlet log文件。

21. void removeAttribute( String name ) ;
      移除指定名称的application属性。

22. void setAttribute( String name, Object value ) ;
      设定指定的application属性的值。


⑦ config - javax.servlet.ServletConfig
     config对象用来存放Servlet初始的数据结构。

方法:
1. String getInitParameter( String name ) ;
     返回名称为name的促使参数的值。

2. Enumeration getInitParameters() ;
     返回这个JSP所有的促使参数的名称集合。

3. ServletContext getContext() ;
     返回执行者的servlet上下文。

4. String getServletName() ;
     返回servlet的名称。


⑧ exception - java.lang.Throwable
     错误对象,只有在JSP页面的page指令中指定isErrorPage="true"后,才可以在本页面使用exception对象。

方法:
1. Throwable fillInStackTrace() ;
     将当前stack信息记录到exception对象中。

2. String getLocalizedMessage() ;
     取得本地语系的错误提示信息。

3. String getMessage()
     取得错误提示信息。

4. StackTrackElement[] getStackTrace() ;
     返回对象中记录的call stack track信息。

5. Throwable initCause( Throwable cause ) ;
     将另外一个异常对象嵌套进当前异常对象中。
   
6. Throwable getCause() ;
     取出嵌套在当前异常对象中的异常。

7. void printStackTrace() ;
     void printStackTrace( printStream s ) ;
     void printStackTrace( printWriter s ) ;
     打印出Throwable及其call stack trace信息。

8. void setStackTrace( StackTraceElement[] stackTrace )
     设置对象的call stack trace信息。


⑨ page - javax.servlet.jsp.HttpJspPage
     page对象代表JSP对象本身,或者说代表编译后的servlet对象,可以用( (javax.servlet.jsp.HttpJspPage)page )来取用它的方法和属性。page对象在页的正文中可以被看作"this"的同义词.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值