1. 程式人生 > >JSP九大內置對象及其方法

JSP九大內置對象及其方法

name line tco exce sco trace 作用範圍 conf pos

內置對象包括

request response pageContext session application out config page exception

1.out
(1)clear()清除緩沖區
(2)flush()刷新緩沖區
(3)newLine() 創建新的一行
(4)print(各種數據類型)顯示數據內容
(5)pringln(各種數據類型)換行顯示數據內容
2.request 向服務器發送請求
(1)getLocale() 獲取本地的語言
(2)getMethod()獲取客戶端的參數方法 post get
(3)getParameter(String name)取得傳入的參數
(4)getParameterNames()取得傳入參數的名字集合
(5)getParameterMap()取得傳入參數的Map集合 參數名和值
(6)getRemoteAddr()取得客戶端的網絡地址
(7)getServerName()取得服務器的名字
(8)getServletPath()獲取servlet的路徑
(9)setCharacterEncoding(String s)設置傳入參數的字符集

3.response
(1)addCookie(Cookie cookie)
(2)sendRedirect()重定向
(3)setBufferSize()設置緩存大小
(4)setContentType()設置客戶端的編碼機制
(5)setLocale()設置客戶端的語言
(6)getWrite()取得內容輸出器

4.session 會話
(1)getAttribute()根據名字取得session的參數值
(2)getAttributeName() 獲取session的參數名
(3)getCreationTime()取得session的創建時間 客戶端的訪問服務器的時間
(4)getId()獲取客戶端的id
(5)getLastAccessTime() 獲取客戶最後一次訪問服務器的時間
(6)getMaxInactiveInterval() 客戶端停止訪問後在服務器的保存時間
(7)isNew() 判斷客戶端是否是第一次訪問服務器
(8)removeAttribute()刪除session的參數
(9)setAttribute()設置session的參數
(10)setMaxInactiveInterval() 設置客戶端停止訪問後在服務器的保存時間
5.application 應用


(1)getAttribute()根據名字取得application的參數值
(2)getAttributeName() 獲取application的參數名
(3)setAttribute()設置application的參數
(4)getMajorVersion()取得服務器支持servlet的版本號
(5)removeAttribute()刪除application的參數
6.config 配置
(1)getInitParameter()根據名字獲取初始化參數值
(2)getInitParameterNames()取得初始化參數名字
7.pageContext 上下文對象
(1)forward()將客戶的請求移動到另一個jsp文件
(2)getAttribute(String name,int scope)根據參數的名字和作用域取得參數值
(3)getAttributeNamesInScope(int scope)取得某個作用域參數名
(4)removeAttribute(String name,int scope)根據參數的名字和作用域刪除參數
(5)setAttribute(String name,Object o,int scope)根據參數的名字和作用範圍創建參數
(6)getException()取得exception對象
(7)getOut()取得out對象
(8)getPage()取得page對象
(9)getRequest()取得request對象
(10)getResponse()取得response對象
(11)getSession()取得session對象
(12)include()在jsp文件中包含其他文件
(13)getServletContext()取得application對象
8.exception 異常

(1)getLocalizedMessage()取得異常信息
(2)getMessage()取得詳細的異常信息
(3)printStackTrace() 在服務器端顯示異常信息
(4)toString() 顯示異常類和信息
9.page

該對象的實質就是java.lang.Object,在JSP文件內沒有實質的應用

JSP九大內置對象及其方法