`
primer_2004
  • 浏览: 124326 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

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"的同义词.

分享到:
评论
1 楼 kanokano 2007-10-26  
primer_2004 写道
<font face="隶书" color="#3366ff" size="4"><strong>⑤ pageContext - javax.servlet.jsp.PageContext<br />
&nbsp;&nbsp;&nbsp;&nbsp; pageContext对象存储本JSP页面相关信息,如属性、内建对象等。</strong></font>
<p><font face="Courier New">方法:<br />
1. void setAttribute( String name, Object value, int scope ) ;<br />
&nbsp;&nbsp;&nbsp;&nbsp; void setAttribute( String name, Object value ) ;<br />
&nbsp;&nbsp;&nbsp;&nbsp; 在指定的共享范围内设置属性。</font></p>
<p><font face="Courier New">2. Object getAttribute( String name, int scope ) ;<br />
&nbsp;&nbsp;&nbsp;&nbsp; Object getAttribute( String name ) ;<br />
&nbsp;&nbsp;&nbsp;&nbsp; 取得指定共享范围内以name为名字的属性值。</font></p>
<p><font face="Courier New">3. Object findAttribute( String name ) ;<br />
&nbsp;&nbsp;&nbsp;&nbsp; 按页面、请求、会话和应用程序共享范围搜索已命名的属性。</font></p>
<p><font face="Courier New">4. void removeAttribute( String name, int scope ) ;<br />
&nbsp;&nbsp;&nbsp;&nbsp; void removeAttribute( String name ) ;<br />
&nbsp;&nbsp;&nbsp;&nbsp; 移除指定名称和共享范围的属性。</font></p>
<p><font face="Courier New">5. void forward( String url ) ;<br />
&nbsp;&nbsp;&nbsp;&nbsp; 将页面导航到指定的URL。</font></p>
<p><font face="Courier New">6. Enumeration getAttributeNamesScope( int scope ) ;<br />
&nbsp;&nbsp;&nbsp;&nbsp; 取得指定共享范围内的所有属性名称的集合。</font></p>
<p><font face="Courier New">7. int getAttributeScope( String name ) ;<br />
&nbsp;&nbsp;&nbsp;&nbsp; 取得指定属性的共享范围。</font></p>
<p><font face="Courier New">8. ErrorData getErrorDate() ;<br />
&nbsp;&nbsp;&nbsp;&nbsp; 取得页面的errorData对象。</font></p>
<p><font face="Courier New">9. Exception getException() ;<br />
&nbsp;&nbsp;&nbsp;&nbsp; 取得页面的exception对象。</font></p>
<p><font face="Courier New">10. ExpressionEvaluator getExpressionEvaluator() ;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 取得页面的expressionEvaluator对象。</font></p>
<p><font face="Courier New">11. JspWriter getOut() ;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 取得页面的out对象。</font></p>
<p><font face="Courier New">12. Object getPage() ;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 取得页面的page对象。</font></p>
<p><font face="Courier New">13. ServletRequest getRequest() ;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 取得页面的request对象。</font></p>
<p><font face="Courier New">14. ServletResponse getResponse() ;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 取得页面的response对象。</font></p>
<p><font face="Courier New">15. ServletConfig getConfig() ;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 取得页面的config对象。</font></p>
<p><font face="Courier New">16. ServletContext getServletContext() ;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 取得页面的servletContext对象。</font></p>
<p><font face="Courier New">17. HttpSession getSession() ;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 取得页面的session对象。</font></p>
<p><font face="Courier New">18. VariableResolver getVariableResolver() ;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 取得页面的variableResolver对象。</font></p>
<p><font face="Courier New">19. void include( String url, boolean flush ) ;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; void include( String url ) ;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 包含其他的资源,并指定是否自动刷新。</font></p>
<p><font face="Courier New">20. void release() ;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 重置pageContext内部状态,释放所有内部引用。</font></p>
<p><font face="Courier New">21. void initialize( Servlet servlet, ServletRequest request, ServletResponse response,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String errorPageURL, boolean needSession, int bufferSize, boolean autoFlush ) ;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 初始化未经初始化的pageContext对象。</font></p>
<p><font face="Courier New">22. BodyContext pushBody() ;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BodyContext pushBody( Writer writer ) ;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 保存当前的out对象,并更新pageContext中page范围内的out对象。</font></p>
<p><font face="Courier New">23. JspWrite popBody() ;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 取出由pushBody()方法保存的out对象。</font></p>
<p><font face="Courier New">24. void handlePageException( Exception e ) ;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; void handlePageException( Thrwoable t ) ;<br />
&nbsp;&nbsp;&nbsp;&nbsp;</font></p>
<p><font face="Courier New">成员:<br />
int PAGE_SCOPE = 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - 页面共享范围<br />
int REQUEST_SCOPE = 2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - 请求共享范围<br />
int SESSION_SCOPE = 3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - 会话共享范围<br />
int APPLICATION_SCOPE = 4 - 应用程序共享范围<br />
String PAGE = &quot;javax.servlet.jsp.jspPage&quot;<br />
String PAGECONTEXT = &quot;javax.servlet.jsp.jspPageContext&quot;<br />
String REQUEST = &quot;javax.servlet.jsp.jspRequest&quot;<br />
String RESPONSE = &quot;javax.servlet.jsp.jspResponse&quot;<br />
String CONFIG = &quot;javax.servlet.jsp.jspConfig&quot;<br />
String SESSION = &quot;javax.servlet.jsp.jspSession&quot;<br />
String OUT = &quot;javax.servlet.jsp.jspOut&quot;<br />
String APPLICATION = &quot;javax.servlet.jsp.jspApplication&quot;<br />
String EXCEPTION = &quot;javax.servlet.jsp.jspException&quot;</font></p>
<p><br />
<strong><font face="隶书" color="#3366ff" size="4">⑥ application - javax.servlet.ServletContext<br />
&nbsp;&nbsp;&nbsp;&nbsp; application主要功用在于取得或更改Servlet的设定。</font></strong></p>
<p><font face="Courier New">方法:<br />
1. Object getAttribute( String name ) ;<br />
&nbsp;&nbsp;&nbsp;&nbsp; 返回由name指定的application属性。</font></p>
<p><font face="Courier New">2. Enumeration getAttributes() ;<br />
&nbsp;&nbsp;&nbsp;&nbsp; 返回所有的application属性。</font></p>
<p><font face="Courier New">3. ServletContext getContext( String uripath ) ;<br />
&nbsp;&nbsp;&nbsp;&nbsp; 取得当前应用的ServletContext对象。</font></p>
<p><font face="Courier New">4. String getInitParameter( String name ) ;<br />
&nbsp;&nbsp;&nbsp;&nbsp; 返回由name指定的application属性的初始值。</font></p>
<p><font face="Courier New">5. Enumeration getInitParameters() ;<br />
&nbsp;&nbsp;&nbsp;&nbsp; 返回所有的application属性的初始值的集合。</font></p>
<p><font face="Courier New">6. int getMajorVersion() ;<br />
&nbsp;&nbsp;&nbsp;&nbsp; 返回servlet容器支持的Servlet API的版本号。</font></p>
<p><font face="Courier New">7. String getMimeType( String file ) ;<br />
&nbsp;&nbsp;&nbsp;&nbsp; 返回指定文件的类型,未知类型返回null。一般为&quot;text/html&quot;和&quot;image/gif&quot;。</font></p>
<p><font face="Courier New">8. int getMinorVersion() ;<br />
&nbsp;&nbsp;&nbsp;&nbsp; 返回servlet容器支持的Servlet API的副版本号。</font></p>
<p><font face="Courier New">9. String getRealPath( String path ) ;<br />
&nbsp;&nbsp;&nbsp;&nbsp; 返回给定虚拟路径所对应物理路径。</font></p>
<p><font face="Courier New">10. RequestDispatcher getNamedDispatcher( String name ) ;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 为指定名字的Servlet对象返回一个RequestDispatcher对象的实例。</font></p>
<p><font face="Courier New">11. RequestDispatcher getRequestDispatcher( String path ) ;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 返回一个RequestDispatcher对象的实例。</font></p>
<p><font face="Courier New">12. URL getResource( String path ) ;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 返回指定的资源路径对应的一个URL对象实例,参数要以&quot;/&quot;开头。</font></p>
<p><font face="Courier New">13. InputStream getResourceAsStream( String path ) ;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 返回一个由path指定位置的资源的InputStream对象实例。</font></p>
<p><font face="Courier New">14. Set getResourcePaths( String path ) ;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 返回存储在web-app中所有资源路径的集合。</font></p>
<p><font face="Courier New">15. String getServerInfo() ;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 取得应用服务器版本信息。</font></p>
<p><font face="Courier New">16. Servlet getServlet( String name ) ;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 在ServletContext中检索指定名称的servlet。</font></p>
<p><font face="Courier New">17. Enumeration getServlets() ;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 返回ServletContext中所有servlet的集合。</font></p>
<p><font face="Courier New">18. String getServletContextName() ;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 返回本web应用的名称。</font></p>
<p><font face="Courier New">19. Enumeration getServletContextNames() ;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 返回ServletContext中所有servlet的名称集合。</font></p>
<p><font face="Courier New">20. void log( Exception ex, String msg ) ;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; void log( String msg, Throwable t ) ;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; void log( String msg ) ;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 把指定的信息写入servlet log文件。</font></p>
<p><font face="Courier New">21. void removeAttribute( String name ) ;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 移除指定名称的application属性。</font></p>
<p><font face="Courier New">22. void setAttribute( String name, Object value ) ;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 设定指定的application属性的值。</font></p>
<p><br />
<strong><font face="隶书" color="#3366ff" size="4">⑦ config - javax.servlet.ServletConfig<br />
&nbsp;&nbsp;&nbsp;&nbsp; config对象用来存放Servlet初始的数据结构。</font></strong></p>
<p><font face="Courier New">方法:<br />
1. String getInitParameter( String name ) ;<br />
&nbsp;&nbsp;&nbsp;&nbsp; 返回名称为name的促使参数的值。</font></p>
<p><font face="Courier New">2. Enumeration getInitParameters() ;<br />
&nbsp;&nbsp;&nbsp;&nbsp; 返回这个JSP所有的促使参数的名称集合。</font></p>
<p><font face="Courier New">3. ServletContext getContext() ;<br />
&nbsp;&nbsp;&nbsp;&nbsp; 返回执行者的servlet上下文。</font></p>
<p><font face="Courier New">4. String getServletName() ;<br />
&nbsp;&nbsp;&nbsp;&nbsp; 返回servlet的名称。</font></p>
<p><br />
<strong><font face="隶书" color="#3366ff" size="4">⑧ exception - java.lang.Throwable<br />
&nbsp;&nbsp;&nbsp;&nbsp; 错误对象,只有在JSP页面的page指令中指定isErrorPage=&quot;true&quot;后,才可以在本页面使用exception对象。</font></strong></p>
<p><font face="Courier New">方法:<br />
1. Throwable fillInStackTrace() ;<br />
&nbsp;&nbsp;&nbsp;&nbsp; 将当前stack信息记录到exception对象中。</font></p>
<p><font face="Courier New">2. String getLocalizedMessage() ;<br />
&nbsp;&nbsp;&nbsp;&nbsp; 取得本地语系的错误提示信息。</font></p>
<p><font face="Courier New">3. String getMessage()<br />
&nbsp;&nbsp;&nbsp;&nbsp; 取得错误提示信息。</font></p>
<p><font face="Courier New">4. StackTrackElement[] getStackTrace() ;<br />
&nbsp;&nbsp;&nbsp;&nbsp; 返回对象中记录的call stack track信息。</font></p>
<p><font face="Courier New">5. Throwable initCause( Throwable cause ) ;<br />
&nbsp;&nbsp;&nbsp;&nbsp; 将另外一个异常对象嵌套进当前异常对象中。<br />
&nbsp;&nbsp;&nbsp;<br />
6. Throwable getCause() ;<br />
&nbsp;&nbsp;&nbsp;&nbsp; 取出嵌套在当前异常对象中的异常。</font></p>
<p><font face="Courier New">7. void printStackTrace() ;<br />
&nbsp;&nbsp;&nbsp;&nbsp; void printStackTrace( printStream s ) ;<br />
&nbsp;&nbsp;&nbsp;&nbsp; void printStackTrace( printWriter s ) ;<br />
&nbsp;&nbsp;&nbsp;&nbsp; 打印出Throwable及其call stack trace信息。</font></p>
<p><font face="Courier New">8. void setStackTrace( StackTraceElement[] stackTrace )<br />
&nbsp;&nbsp;&nbsp;&nbsp; 设置对象的call stack trace信息。</font></p>
<p><br />
<strong><font face="隶书" color="#3366ff" size="4">⑨ page - javax.servlet.jsp.HttpJspPage<br />
&nbsp;&nbsp;&nbsp;&nbsp; page对象代表JSP对象本身,或者说代表编译后的servlet对象,可以用( (javax.servlet.jsp.HttpJspPage)page )来取用它的方法和属性。page对象在页的正文中可以被看作&quot;this&quot;的同义词.</font></strong></p>
收藏!!!!

相关推荐

Global site tag (gtag.js) - Google Analytics