国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JSP > 正文

JSP的九個隱含對象

2024-09-05 00:19:55
字體:
來源:轉載
供稿:網友

  一、page 對象

    page對象代表jsp本身,更準確地說它代表jsp被轉譯后的servlet,它可以調用servlet類所定義的方法。
    
  二、config 對象

    config 對象里存放著一些servlet 初始的數據結構。
    config 對象實現于javax.servlet.servletconfig 接口,它共有下列四種方法:
        public string getinitparameter(name)
        public java.util.enumeration getinitparameternames( )
        public servletcontext getservletcontext( )
        public sring getservletname( )

  三、request 對象

    request 對象包含所有請求的信息,如:請求的來源、標頭、cookies和請求相關的參數值等等。
    request 對象實現javax.servlet.http.httpservletrequest接口的,所提供的方法可以將它分為四大類:
    1.儲存和取得屬性方法;
        void setattribute(string name, object value)    設定name屬性的值為value
        enumeration getattributenamesinscope(int scope)    取得所有scope 范圍的屬性
        object getattribute(string name)                取得name 屬性的值
        void removeattribute(string name)                移除name 屬性的值
    2.取得請求參數的方法
        string getparameter(string name)                取得name 的參數值
        enumeration getparameternames( )                取得所有的參數名稱
        string [] getparametervalues(string name)         取得所有name 的參數值
        map getparametermap( )                             取得一個要求參數的map
    3.能夠取得請求http 標頭的方法
        string getheader(string name)                     取得name 的標頭
        enumeration getheadernames()                     取得所有的標頭名稱
        enumeration getheaders(string name)             取得所有name 的標頭
        int getintheader(string name)                     取得整數類型name 的標頭
        long getdateheader(string name)                 取得日期類型name 的標頭
        cookie [] getcookies( )                         取得與請求有關的cookies
    4.其他的方法
        string getcontextpath( )                         取得context 路徑(即站臺名稱)
        string getmethod( )                             取得http 的方法(get、post)
        string getprotocol( )                             取得使用的協議 (http/1.1、http/1.0 )
        string getquerystring( )                        取得請求的參數字符串,不過,http的方法必須為get
        string getrequestedsessionid( )                 取得用戶端的session id
        string getrequesturi( )                            取得請求的url,但是不包括請求的參數字符串
        string getremoteaddr( )                            取得用戶的ip 地址
        string getremotehost( )                            取得用戶的主機名稱
        int getremoteport( )                            取得用戶的主機端口
        string getremoteuser( )                         取得用戶的名稱
        void etcharacterencoding(string    encoding)        設定編碼格式,用來解決窗體傳遞中文的問題

  四、response 對象

    response 對象主要將jsp 處理數據后的結果傳回到客戶端。
    response 對象是實現javax.servlet.http.httpservletresponse 接口。response對象所提供的方法。
    1.設定表頭的方法
        void addcookie(cookie cookie)                     新增cookie
        void adddateheader(string name, long date)        新增long類型的值到name標頭
        void addheader(string name, string value)        新增string類型的值到name標頭
        void addintheader(string name, int value)         新增int類型的值到name標頭
        void setdateheader(string name, long date)        指定long類型的值到name標頭
        void setheader(string name, string value)        指定string類型的值到name標頭
        void setintheader(string name, int value)         指定int類型的值到name標頭
    2.設定響應狀態碼的方法
        void senderror(int sc)                             傳送狀態碼(status code)
        void senderror(int sc, string msg)                傳送狀態碼和錯誤信息
        void setstatus(int sc)                             設定狀態碼
    3.用來url 重寫(rewriting)的方法    
        string encoderedirecturl(string    url)            對使用sendredirect( )方法的url予以編碼

  五、out 對象

    out 對象能把結果輸出到網頁上。
    out主要是用來控制管理輸出的緩沖區(buffer)和輸出流(output stream)。
        void clear( )                                     清除輸出緩沖區的內容
        void clearbuffer( )                             清除輸出緩沖區的內容
        void close( )                                     關閉輸出流,清除所有的內容
        int getbuffersize( )                             取得目前緩沖區的大小(kb)
        int getremaining( )                             取得目前使用后還剩下的緩沖區大小(kb)
        boolean isautoflush( )                            回傳true表示緩沖區滿時會自動清除;false表示不會自動清除并且產生異常處理
        
  六、session 對象

    session對象表示目前個別用戶的會話(session)狀況。
    session對象實現javax.servlet.http.httpsession接口,httpsession接口所提供的方法
        long getcreationtime()                            取得session產生的時間,單位是毫秒
        string getid()                                     取得session 的id
        long getlastaccessedtime()                        取得用戶最后通過這個session送出請求的時間
        long getmaxinactiveinterval()                    取得最大session不活動的時間,若超過這時間,session 將會失效
        void invalidate()                                取消session 對象,并將對象存放的內容完全拋棄
        boolean isnew()                                    判斷session 是否為"新"的
        void setmaxinactiveinterval(int    interval)        設定最大session不活動的時間,若超過這時間,session 將會失效

  七、application對象

    application對象最常被使用在存取環境的信息。
    因為環境的信息通常都儲存在servletcontext中,所以常利用application對象來存取servletcontext中的信息。
    application 對象實現javax.servlet.servletcontext 接口,servletcontext接口容器所提供的方法
        int getmajorversion( )                             取得container主要的servlet api版本
        int getminorversion( )                             取得container次要的servlet api 版本
        string getserverinfo( )                         取得container的名稱和版本
        string getmimetype(string file)                 取得指定文件的mime 類型
        servletcontext getcontext(string uripath)        取得指定local url的application context
        string getrealpath(string path)                 取得本地端path的絕對路徑
        void log(string message)                         將信息寫入log文件中
        void log(string message, throwable throwable)    將stack trace 所產生的異常信息寫入log文件中

  八、pagecontext對象

    pagecontext對象能夠存取其他隱含對象。
    1.pagecontext對象存取其他隱含對象屬性的方法,此時需要指定范圍的參數。
        object getattribute(string name, int scope)
        enumeration getattributenamesinscope(int scope)
        void removeattribute(string name, int scope)
        void setattribute(string name, object value, int scope)
    范圍參數有四個,分別代表四種范圍:page_scope、request_scope、session_scope、application_scope
    2.pagecontext對象取得其他隱含對象的方法
        exception getexception( )                        回傳目前網頁的異常,不過此網頁要為error page,
        jspwriter getout( )                             回傳目前網頁的輸出流,例如:out 
        object getpage( )                                回傳目前網頁的servlet 實體(instance),例如:page
        servletrequest getrequest( )                    回傳目前網頁的請求,例如:request
        servletresponse getresponse( )                    回傳目前網頁的響應,例如:response
        servletconfig getservletconfig( )                回傳目前此網頁的servletconfig 對象,例如:config
        servletcontext getservletcontext( )                回傳目前此網頁的執行環境(context),例如:application
        httpsession getsession( )                        回傳和目前網頁有聯系的會話(session),例如:session
    3.pagecontext對象提供取得屬性的方法
        object getattribute(string name, int scope)        回傳name 屬性,范圍為scope的屬性對象,回傳類型為object
        enumeration getattributenamesinscope(int scope)    回傳所有屬性范圍為scope 的屬性名稱,回傳類型為enumeration
        int getattributesscope(string name)             回傳屬性名稱為name 的屬性范圍
        void removeattribute(string name)                 移除屬性名稱為name 的屬性對象
        void removeattribute(string name, int scope)    移除屬性名稱為name,范圍為scope 的屬性對象
        void setattribute(string name, object value, int scope)        指定屬性對象的名稱為name、值為value、范圍為scope
        object findattribute(string name)                尋找在所有范圍中屬性名稱為name 的屬性對象

  九、exception對象

    若要使用exception 對象時,必須在page 指令中設定。<%@ page iserrorpage="true" %>才能使用。
    exception提供的三個方法:
        getmessage( )
        getlocalizedmessage( )、
        printstacktrace(new java.io.printwriter(out)) 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 冕宁县| 海安县| 京山县| 萝北县| 河北区| 民乐县| 黎川县| 茂名市| 兴文县| 禄丰县| 河西区| 利川市| 山东省| 兰州市| 香格里拉县| 依兰县| 当雄县| 东乌珠穆沁旗| 双城市| 郓城县| 葵青区| 吕梁市| 聊城市| 文成县| 齐河县| 丹棱县| 麦盖提县| 巴南区| 德化县| 乾安县| 宣化县| 伊吾县| 昌宁县| 铁岭县| 大足县| 水城县| 恩施市| 南靖县| 昆山市| 漠河县| 青河县|