標籤:erro date attribute char 轉換 param hash info cto
JSP內建對象(9個常用的內建對象)
1.request對象
用戶端的請求資訊被封裝在request對象中,通過它才能瞭解到客戶的需求,
然後做出響應。它是HttpServletRequest類的執行個體。
序號方法說明
- objectgetAttribute(Stringname) 返回指定屬性的屬性值
- EnumerationgetAttributeNames() 返回所有可用屬性名稱的枚舉
- StringgetCharacterEncoding() 返回字元編碼方式
- intgetContentLength() 返回請求體的長度(以位元組數)
- StringgetContentType() 得到請求體的MIME類型
- ServletInputStreamgetInputStream() 得到請求體中一行的二進位流
- StringgetParameter(Stringname) 返回name指定參數的參數值
- EnumerationgetParameterNames() 返回可用參數名的枚舉
- String[]getParameterValues(Stringname) 返回包含參數name的所有值的數組
- StringgetProtocol() 返回請求用的協議類型及版本號碼
- StringgetScheme() 返回請求用的計劃名,如:http.https及ftp等
- StringgetServerName() 返回接受請求的伺服器主機名稱
- intgetServerPort() 返回伺服器接受此請求所用的連接埠號碼
- BufferedReadergetReader() 返回解碼過了的請求體
- StringgetRemoteAddr() 返回傳送此請求的用戶端IP地址
- StringgetRemoteHost() 返回傳送此請求的用戶端主機名稱
- voidsetAttribute(Stringkey,Objectobj) 設定屬性的屬性值
- StringgetRealPath(Stringpath) 返回一虛擬路徑的真實路徑
- 2.response對象
- response對象包含了響應客戶請求的有關資訊,但在JSP中很少直接用到它。
- 它是HttpServletResponse類的執行個體。
- 序號方法說明
- 1StringgetCharacterEncoding() 返迴響應用的是何種字元編碼
- 2ServletOutputStreamgetOutputStream() 返迴響應的一個二進位輸出資料流
- 3PrintWritergetWriter() 返回可以向用戶端輸出字元的一個對象
- 4voidsetContentLength(intlen) 設定回應標頭長度
- 5voidsetContentType(Stringtype) 設定響應的MIME類型
- 6sendRedirect(java.lang.Stringlocation) 重新定向用戶端的請求
3.session對象
session對象指的是用戶端與伺服器的一次會話,從客戶連到伺服器的一個
WebApplication開始,直到用戶端與伺服器中斷連線為止。它是HttpSession
類的執行個體.
序號方法說明
- longgetCreationTime() 返回SESSION建立時間
- publicStringgetId() 返回SESSION建立時JSP引擎為它設的惟一ID號
- longgetLastAccessedTime() 返回此SESSION裡用戶端最近一次請求時間
- intgetMaxInactiveInterval() 返回兩次請求間隔多長時間此SESSION被取
- 消(ms)
- String[]getValueNames() 返回一個包含此SESSION中所有可用屬性的數
- 組
- voidinvalidate() 取消SESSION,使SESSION不可用
- booleanisNew() 返回伺服器建立的一個SESSION,用戶端是否已經加入
- voidremoveValue(Stringname) 刪除SESSION中指定的屬性
- voidsetMaxInactiveInterval() 設定兩次請求間隔多長時間此SESSION被取
消(ms)
4.out對象
- out對象是JspWriter類的執行個體,是向用戶端輸出內容常用的對象
- 序號方法說明
- voidclear() 清除緩衝區的內容
- voidclearBuffer() 清除緩衝區的當前內容
- voidflush() 清空流
- intgetBufferSize() 返回緩衝區以位元組數的大小,如不設緩衝區則為0
- intgetRemaining() 返回緩衝區還剩餘多少可用
- booleanisAutoFlush() 返回緩衝區滿時,是自動清空還是拋出異常
- voidclose() 關閉輸出資料流
5.page對象
- page對象就是指向當前JSP頁面本身,有點象類中的this指標,它是
- java.lang.Object類的執行個體
- 序號方法說明
- classgetClass 返回此Object的類
- inthashCode() 返回此Object的hash碼
- booleanequals(Objectobj) 判斷此Object是否與指定的Object對象相等
- voidcopy(Objectobj) 把此Object拷貝到指定的Object對象中
- Objectclone() 複製此Object對象
- StringtoString() 把此Object對象轉換成String類的對象
- voidnotify() 喚醒一個等待的線程
- voidnotifyAll() 喚醒所有等待的線程
- voidwait(inttimeout) 使一個線程處於等待直到timeout結束或被喚醒
- voidwait() 使一個線程處於等待直到被喚醒
- voidenterMonitor() 對Object加鎖
- voidexitMonitor() 對Object開鎖
6.application對象
application對象實現了使用者間資料的共用,可存放全域變數。它開始於伺服器
的啟動,直到伺服器的關閉,在此期間,此對象將一直存在;這樣在使用者的前
後串連或不同使用者之間的串連中,可以對此對象的同一屬性進行操作;在任何
地方對此對象屬性的操作,都將影響到其他使用者對此的訪問。伺服器的啟動和
關閉決定了application對象的生命。它是ServletContext類的執行個體。
序號方法說明
- ObjectgetAttribute(Stringname) 返回給定名的屬性值
- EnumerationgetAttributeNames() 返回所有可用屬性名稱的枚舉
- voidsetAttribute(Stringname,Objectobj) 設定屬性的屬性值
- voidremoveAttribute(Stringname) 刪除一屬性及其屬性值
- StringgetServerInfo() 返回JSP(SERVLET)引擎名及版本號碼
- StringgetRealPath(Stringpath) 返回一虛擬路徑的真實路徑
- ServletContextgetContext(Stringuripath) 返回指定WebApplication的application對象
- intgetMajorVersion() 返回伺服器支援的ServletAPI的最大版本號碼
- intgetMinorVersion() 返回伺服器支援的ServletAPI的最大版本號碼
- StringgetMimeType(Stringfile) 返回指定檔案的MIME類型
- URLgetResource(Stringpath) 返回指定資源(檔案及目錄)的URL路徑
- InputStreamgetResourceAsStream(Stringpath) 返回指定資源的輸入資料流
- RequestDispatchergetRequestDispatcher(Stringuripath) 返回指定資源的RequestDispatcher對象
- ServletgetServlet(Stringname) 返回指定名的Servlet
- EnumerationgetServlets() 返回所有Servlet的枚舉
- EnumerationgetServletNames() 返回所有Servlet名的枚舉
- voidlog(Stringmsg) 把指定訊息寫入Servlet的記錄檔
- voidlog(Exceptionexception,Stringmsg) 把指定異常的棧軌跡及錯誤訊息寫入Servlet的記錄檔
- voidlog(Stringmsg,Throwablethrowable) 把棧軌跡及給出的Throwable異常的說明資訊寫入Servlet的記錄檔
7.exception對象
exception對象是一個例外對象,當一個頁面在運行過程中發生了例外,就產
生這個對象。如果一個JSP頁面要應用此對象,就必須把isErrorPage設為true,
否則無法編譯。他實際上是Java.lang.Throwable的對象
序號方法說明
- StringgetMessage() 返回描述異常的訊息
- StringtoString() 返回關於異常的簡短描述訊息
- voidprintStackTrace() 顯示異常及其棧軌跡
- ThrowableFillInStackTrace() 重寫異常的執行棧軌跡
8.pageContext對象
pageContext對象提供了對JSP頁面內所有的對象及名字空間的訪問,也就是
說他可以訪問到本頁所在的SESSION,也可以取本頁面所在的application的
某一屬性值,他相當於頁面中所有功能的集大成者,它的本類名也叫
pageContext。
序號方法說明
- JspWritergetOut() 返回當前用戶端響應被使用的JspWriter流(out)
- HttpSessiongetSession() 返回當前頁中的HttpSession對象(session)
- ObjectgetPage() 返回當前頁的Object對象(page)
- ServletRequestgetRequest() 返回當前頁的ServletRequest對象(request)
- ServletResponsegetResponse() 返回當前頁的ServletResponse對象(response)
- ExceptiongetException() 返回當前頁的Exception對象(exception)
- ServletConfiggetServletConfig() 返回當前頁的ServletConfig對象(config)
- ServletContextgetServletContext() 返回當前頁的ServletContext對象(application)
- voidsetAttribute(Stringname,Objectattribute) 設定屬性及屬性值
- voidsetAttribute(Stringname,Objectobj,intscope) 在指定範圍內設定屬性及屬性值
- publicObjectgetAttribute(Stringname) 取屬性的值
- ObjectgetAttribute(Stringname,intscope) 在指定範圍內取屬性的值
- publicObjectfindAttribute(Stringname) 尋找一屬性,返回起屬性值或NULL
- voidremoveAttribute(Stringname) 刪除某屬性
- voidremoveAttribute(Stringname,intscope) 在指定範圍刪除某屬性
- intgetAttributeScope(Stringname) 返回某屬性的作用範圍
- EnumerationgetAttributeNamesInScope(intscope) 返回指定範圍內可用的屬性名稱枚舉
- voidrelease() 釋放pageContext所佔用的資源
- voidforward(StringrelativeUrlPath) 使當前頁面重導到另一頁面
- voidinclude(StringrelativeUrlPath) 在當前位置包含另一檔案
9.config對象
config對象是在一個Servlet初始化時,JSP引擎向它傳遞資訊用的,此資訊包括Servlet初始化時所要用到的參數(通過屬性名稱和屬性值構成)以及伺服器的有關資訊(通過傳遞一個ServletContext對象)
jsp的內建對象