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"的同義詞.