jsp的內建對象

來源:互聯網
上載者:User

標籤:erro   date   attribute   char   轉換   param   hash   info   cto   

JSP內建對象(9個常用的內建對象)

   1.request對象

用戶端的請求資訊被封裝在request對象中,通過它才能瞭解到客戶的需求,

然後做出響應。它是HttpServletRequest類的執行個體。

序號方法說明

  1. objectgetAttribute(Stringname) 返回指定屬性的屬性值
  2. EnumerationgetAttributeNames() 返回所有可用屬性名稱的枚舉
  3. StringgetCharacterEncoding() 返回字元編碼方式
  4. intgetContentLength() 返回請求體的長度(以位元組數)
  5. StringgetContentType() 得到請求體的MIME類型
  6. ServletInputStreamgetInputStream() 得到請求體中一行的二進位流
  7. StringgetParameter(Stringname) 返回name指定參數的參數值
  8. EnumerationgetParameterNames() 返回可用參數名的枚舉
  9. String[]getParameterValues(Stringname) 返回包含參數name的所有值的數組
  10. StringgetProtocol() 返回請求用的協議類型及版本號碼
  11. StringgetScheme() 返回請求用的計劃名,如:http.https及ftp等
  12. StringgetServerName() 返回接受請求的伺服器主機名稱
  13. intgetServerPort() 返回伺服器接受此請求所用的連接埠號碼
  14. BufferedReadergetReader() 返回解碼過了的請求體
  15. StringgetRemoteAddr() 返回傳送此請求的用戶端IP地址
  16. StringgetRemoteHost() 返回傳送此請求的用戶端主機名稱
  17. voidsetAttribute(Stringkey,Objectobj) 設定屬性的屬性值
  18. StringgetRealPath(Stringpath) 返回一虛擬路徑的真實路徑
  19.    2.response對象
  20. response對象包含了響應客戶請求的有關資訊,但在JSP中很少直接用到它。
  21. 它是HttpServletResponse類的執行個體。
  22. 序號方法說明
  23. 1StringgetCharacterEncoding() 返迴響應用的是何種字元編碼
  24. 2ServletOutputStreamgetOutputStream() 返迴響應的一個二進位輸出資料流
  25. 3PrintWritergetWriter() 返回可以向用戶端輸出字元的一個對象
  26. 4voidsetContentLength(intlen) 設定回應標頭長度
  27. 5voidsetContentType(Stringtype) 設定響應的MIME類型
  28. 6sendRedirect(java.lang.Stringlocation) 重新定向用戶端的請求

   3.session對象

session對象指的是用戶端與伺服器的一次會話,從客戶連到伺服器的一個

WebApplication開始,直到用戶端與伺服器中斷連線為止。它是HttpSession

類的執行個體.

序號方法說明

  1. longgetCreationTime() 返回SESSION建立時間
  2. publicStringgetId() 返回SESSION建立時JSP引擎為它設的惟一ID號
  3. longgetLastAccessedTime() 返回此SESSION裡用戶端最近一次請求時間
  4. intgetMaxInactiveInterval() 返回兩次請求間隔多長時間此SESSION被取
  5. 消(ms)
  6. String[]getValueNames() 返回一個包含此SESSION中所有可用屬性的數
  7. voidinvalidate() 取消SESSION,使SESSION不可用
  8. booleanisNew() 返回伺服器建立的一個SESSION,用戶端是否已經加入
  9. voidremoveValue(Stringname) 刪除SESSION中指定的屬性
  10. voidsetMaxInactiveInterval() 設定兩次請求間隔多長時間此SESSION被取

消(ms)

   4.out對象

  1. out對象是JspWriter類的執行個體,是向用戶端輸出內容常用的對象
  2. 序號方法說明
  3. voidclear() 清除緩衝區的內容
  4. voidclearBuffer() 清除緩衝區的當前內容
  5. voidflush() 清空流
  6. intgetBufferSize() 返回緩衝區以位元組數的大小,如不設緩衝區則為0
  7. intgetRemaining() 返回緩衝區還剩餘多少可用
  8. booleanisAutoFlush() 返回緩衝區滿時,是自動清空還是拋出異常
  9. voidclose() 關閉輸出資料流

   5.page對象

  1. page對象就是指向當前JSP頁面本身,有點象類中的this指標,它是
  2. java.lang.Object類的執行個體
  3. 序號方法說明
  4. classgetClass 返回此Object的類
  5. inthashCode() 返回此Object的hash碼
  6. booleanequals(Objectobj) 判斷此Object是否與指定的Object對象相等
  7. voidcopy(Objectobj) 把此Object拷貝到指定的Object對象中
  8. Objectclone() 複製此Object對象
  9. StringtoString() 把此Object對象轉換成String類的對象
  10. voidnotify() 喚醒一個等待的線程
  11. voidnotifyAll() 喚醒所有等待的線程
  12. voidwait(inttimeout) 使一個線程處於等待直到timeout結束或被喚醒
  13. voidwait() 使一個線程處於等待直到被喚醒
  14. voidenterMonitor() 對Object加鎖
  15. voidexitMonitor() 對Object開鎖

   6.application對象

application對象實現了使用者間資料的共用,可存放全域變數。它開始於伺服器

的啟動,直到伺服器的關閉,在此期間,此對象將一直存在;這樣在使用者的前

後串連或不同使用者之間的串連中,可以對此對象的同一屬性進行操作;在任何

地方對此對象屬性的操作,都將影響到其他使用者對此的訪問。伺服器的啟動和

關閉決定了application對象的生命。它是ServletContext類的執行個體。

序號方法說明

  1. ObjectgetAttribute(Stringname) 返回給定名的屬性值
  2. EnumerationgetAttributeNames() 返回所有可用屬性名稱的枚舉
  3. voidsetAttribute(Stringname,Objectobj) 設定屬性的屬性值
  4. voidremoveAttribute(Stringname) 刪除一屬性及其屬性值
  5. StringgetServerInfo() 返回JSP(SERVLET)引擎名及版本號碼
  6. StringgetRealPath(Stringpath) 返回一虛擬路徑的真實路徑
  7. ServletContextgetContext(Stringuripath) 返回指定WebApplication的application對象
  8. intgetMajorVersion() 返回伺服器支援的ServletAPI的最大版本號碼
  9. intgetMinorVersion() 返回伺服器支援的ServletAPI的最大版本號碼
  10. StringgetMimeType(Stringfile) 返回指定檔案的MIME類型
  11. URLgetResource(Stringpath) 返回指定資源(檔案及目錄)的URL路徑
  12. InputStreamgetResourceAsStream(Stringpath) 返回指定資源的輸入資料流
  13. RequestDispatchergetRequestDispatcher(Stringuripath) 返回指定資源的RequestDispatcher對象
  14. ServletgetServlet(Stringname) 返回指定名的Servlet
  15. EnumerationgetServlets() 返回所有Servlet的枚舉
  16. EnumerationgetServletNames() 返回所有Servlet名的枚舉
  17. voidlog(Stringmsg) 把指定訊息寫入Servlet的記錄檔
  18. voidlog(Exceptionexception,Stringmsg) 把指定異常的棧軌跡及錯誤訊息寫入Servlet的記錄檔
  19. voidlog(Stringmsg,Throwablethrowable) 把棧軌跡及給出的Throwable異常的說明資訊寫入Servlet的記錄檔

   7.exception對象

exception對象是一個例外對象,當一個頁面在運行過程中發生了例外,就產

生這個對象。如果一個JSP頁面要應用此對象,就必須把isErrorPage設為true,

否則無法編譯。他實際上是Java.lang.Throwable的對象

序號方法說明

  1. StringgetMessage() 返回描述異常的訊息
  2. StringtoString() 返回關於異常的簡短描述訊息
  3. voidprintStackTrace() 顯示異常及其棧軌跡
  4. ThrowableFillInStackTrace() 重寫異常的執行棧軌跡

   8.pageContext對象

pageContext對象提供了對JSP頁面內所有的對象及名字空間的訪問,也就是

說他可以訪問到本頁所在的SESSION,也可以取本頁面所在的application的

某一屬性值,他相當於頁面中所有功能的集大成者,它的本類名也叫

pageContext。

序號方法說明

  1. JspWritergetOut() 返回當前用戶端響應被使用的JspWriter流(out)
  2. HttpSessiongetSession() 返回當前頁中的HttpSession對象(session)
  3. ObjectgetPage() 返回當前頁的Object對象(page)
  4. ServletRequestgetRequest() 返回當前頁的ServletRequest對象(request)
  5. ServletResponsegetResponse() 返回當前頁的ServletResponse對象(response)
  6. ExceptiongetException() 返回當前頁的Exception對象(exception)
  7. ServletConfiggetServletConfig() 返回當前頁的ServletConfig對象(config)
  8. ServletContextgetServletContext() 返回當前頁的ServletContext對象(application)
  9. voidsetAttribute(Stringname,Objectattribute) 設定屬性及屬性值
  10. voidsetAttribute(Stringname,Objectobj,intscope) 在指定範圍內設定屬性及屬性值
  11. publicObjectgetAttribute(Stringname) 取屬性的值
  12. ObjectgetAttribute(Stringname,intscope) 在指定範圍內取屬性的值
  13. publicObjectfindAttribute(Stringname) 尋找一屬性,返回起屬性值或NULL
  14. voidremoveAttribute(Stringname) 刪除某屬性
  15. voidremoveAttribute(Stringname,intscope) 在指定範圍刪除某屬性
  16. intgetAttributeScope(Stringname) 返回某屬性的作用範圍
  17. EnumerationgetAttributeNamesInScope(intscope) 返回指定範圍內可用的屬性名稱枚舉
  18. voidrelease() 釋放pageContext所佔用的資源
  19. voidforward(StringrelativeUrlPath) 使當前頁面重導到另一頁面
  20. voidinclude(StringrelativeUrlPath) 在當前位置包含另一檔案

   9.config對象

config對象是在一個Servlet初始化時,JSP引擎向它傳遞資訊用的,此資訊包括Servlet初始化時所要用到的參數(通過屬性名稱和屬性值構成)以及伺服器的有關資訊(通過傳遞一個ServletContext對象)

jsp的內建對象

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.