① out - javax.servlet.jsp.jspwriter
out對象用于把結果輸出到網頁上。
方法:
1. void clear() ;
清除輸出緩沖區的內容,但是不輸出到客戶端。
2. void clearbuffer() ;
清除輸出緩沖區的內容,并輸出到客戶端。
3. void close() ;
關閉輸出流,清除所有內容。
4. void flush() ;
輸出緩沖區里面的數據。
5. int getbuffersize() ;
獲取以kb為單位的目前緩沖區大小。
6. int getremaining() ;
獲取以kb為單位的緩沖區中未被占用的空間大小。
7. boolean isautoflush() ;
是否自動刷新緩沖區。
8. void newline() ;
輸出一個換行字符。
9. void print( boolean b ) ;
void print( char c ) ;
void print( char[] s ) ;
void print( double d ) ;
void print( float f ) ;
void print( int i ) ;
void print( long l ) ;
void print( object obj ) ;
void print( string s ) ;
將指定類型的數據輸出到http流,不換行。
10. void println( boolean b ) ;
void println( char c ) ;
void println( char[] s ) ;
void println( double d ) ;
void println( float f ) ;
void println( int i ) ;
void println( long l ) ;
void println( object obj ) ;
void println( string s ) ;
將指定類型的數據輸出到http流,并輸出一個換行符。
11. appendable append( char c ) ;
appendable append( charsequence cxq, int start, int end ) ;
appendable append( charsequence cxq ) ;
將一個字符或者實現了charsequence接口的對象添加到輸出流的后面。
成員:
int default_buffer = 0 - 缺省緩沖區大小
int no_buffer = -1 - writer是否處于緩沖輸出狀態
int unbounded_buffer = -2 - 是否限制緩沖區大小
② request - javax.servlet.http.httpservletrequest
request對象包含所有請求的信息,如請求的來源、標頭、cookies和請求相關的參數值等。
方法:
1. object getattribute( string name ) ;
返回由name指定的屬性值,該屬性不存在時返回null。
2. enumeration getattributenames() ;
返回request對象的所有屬性名稱的集合。
3. string getauthtype() ;
返回用來保護servlet的認證方法的名稱,未受保護時返回null。
4. string getcharacterencoding() ;
返回請求中的字符編碼方法,可以在response對象中設置。
5. int getcontentlength() ;
返回請求的body的長度,不能確定長度時返回-1??梢栽趓esponse中設置。
6. string getcontenttype() ;
返回在response中定義的內容類型。
7. string getcontentpath() ;
返回請求的路徑。
8. cookie[] getcookies() ;
返回客戶端所有的cookie的數組。
9. enumeration getheadernames() ;
返回所有http頭的名稱的集合。
10. enumeration getheaders( string name ) ;
返回指定http頭的所有值的集合。
11. string getheader( string name ) ;
返回指定名稱的http頭的信息。
12. long getdateheader( string name ) ;
返回指定名稱的data類型的http頭的信息。
13. int getintheader( string name ) ;
返回指定名稱的int類型的http頭的信息。
14. servletinputstream getinputstream() ;
返回請求的輸入流。
15. locale getlocale() ;
返回當前頁的locale對象,可以在response中設定。
16. enumeration getlocales() ;
返回請求中所有的locale對象的集合。
17. string getlocalname() ;
獲取響應請求的服務器端主機名。
18. string getlocaladdr() ;
獲取響應請求的服務器端地址。
19. int getlocalport() ;
獲取響應請求的服務器端端口
20. string getmethod() ;
獲取客戶端向服務器端發送請求的方法(get、post)。
21. string getparameter( string name ) ;
獲取客戶端發送給服務器端的參數值。
22. map getparametermap() ;
該方法返回包含請求中所有參數的一個map對象。
23. enumeration getparameternames() ;
返回請求中所有參數的集合。
24. string[] getparametervalues( string name ) ;
獲得請求中指定參數的所有值。
25. string getquerystring() ;
返回get方法傳遞的參數字符串,該方法不分解出單獨的參數。
26. string getpathinfo() ;
取出請求中處于servletpath和querystring之間的額外信息。
27. string getpathtranslated() ;
返回用getpathinfo()方法取得的路徑信息的實際路徑。
28. string getprotocol() ;
返回請求使用的協議??梢允莌ttp1.1或者http1.0。
29. bufferedreader getreader() ;
返回請求的輸入流對應的reader對象,該方法和getinputstream()方法在一個頁面中只能調用一個。
30. string getremoteaddr() ;
獲取發出請求的客戶端ip地址。
31. string getremotehost() ;
獲取發出請求的客戶端主機名
32. string getremoteuser() ;
返回經過客戶端驗證的用戶名,未經驗證返回null。
33. int getremoteport() ;
返回發出請求的客戶端主機端口。
34. string getrealpath( string path ) ;
返回給定虛擬路徑的物理路徑。
35. requestdispatcher getrequestdispatcher( string path ) ;
按給定的路徑生成資源轉向處理適配器對象。
36. string getrequestedsessionid() ;
返回請求的session的標識。
37. string requesturi() ;
返回發出請求的客戶端地址,但是不包括請求的參數字符串。
38. stringbuffer getrequesturi() ;
返回響應請求的服務器端地址
39. string getscheme() ;
獲取協議名稱,缺省值為http協議。
40. string getservername() ;
返回響應請求的服務器名稱。
41. string getservletpath() ;
獲取客戶端所請求的腳本文件的文件路徑。
42. int getserverport() ;
獲取響應請求的服務器端主機端口號。
43. void removeattribute( string name ) ;
在屬性列表中刪除指定名稱的屬性。
44. void setattribute( string name, object value ) ;
在屬性列表中添加/刪除指定的屬性。
45. void setcharacterencoding( string name ) ;
設置請求的字符編碼格式。
46. httpsession getsession() ;
httpsession getsession( boolean create ) ;
獲取session,如果create為true,在無session的情況下創建一個。
47. boolean isrequestedsessionidfromcookie() ;
檢查請求的會話id是否為通過cookie傳入。
48. boolean isrequestedsessionidfromurl() ;
檢查請求的會話id是否為通過url傳入。
49. boolean isrequestedsessionidvalid() ;
檢查請求的會話id是否仍然有效。
50. boolean issecure() ;
檢查請求是否使用安全鏈接,如果https等。
51. boolean isuserinrole( string role ) ;
檢查已經通過驗證的用戶是否在是role所指定的角色。
52. principal getuserprincipal() ;
返回包含用戶登陸名的一個java.security.principal對象。
成員:
string basic_auth = "basic" -
string client_cert_auth = "client_cert" -
string digest_auth = "digest" -
string form_auth = "form" -
③ response - javax.servlet.http.httpservletresponse
response對象主要將jsp容器處理后的結果傳回到客戶端。
方法:
1. void addcookie( cookie cookie ) ;
添加一個cookie對象,保存客戶端信息。
2. void adddateheader( string name, long value ) ;
添加一個日期類型的http頭信息,覆蓋同名的http頭信息。
3. void addheader( string name, string value ) ;
添加一個http頭,覆蓋同名的舊http頭。
4. void addintheader( string name, int value ) ;
添加一個整型的http頭,覆蓋同名的舊http頭。
5. boolean containsheader( string name ) ;
判斷指定的http頭是否存在。
6. string encoderedirecturl( string url ) ;
對sendredirect()方法使用的url進行編碼。
7. string encodeurl( string url ) ;
將url予以編碼,回傳包含session id的url。
8. void flushbuffer() ;
強制把當前緩沖區的內容發送到客戶端。
9. int getbuffersize() ;
取得以kb為單位的緩沖區大小。
10. string getcharacterencoding() ;
獲取響應的字符編碼格式。
11. string getcontenttype() ;
獲取響應的類型。
12. locale getlocale() ;
獲取響應的locale對象。
13. servletoutputstream getoutputstream() ;
返回客戶端的輸出流對象。
14. printwriter getwriter() ;
獲取輸出流對應的writer對象。
15. boolean iscommitted() ;
判斷服務器端是否已經將數據輸出到客戶端。
16. void reset() ;
清空buffer中的所有內容。
17. void resetbuffer() ;
情況buffer中所有的內容,但是保留http頭和狀態信息。
18. void senderror( int xc, string msg ) ;
void senderror( int xc ) ;
發送錯誤,包括狀態碼和錯誤信息。
19. void sendredirect( string locationg ) ;
把響應發送到另外一個位置進行處理。
20. void setbuffersize( int size ) ;
設置以kb為單位的緩沖區大小。
21. void setcharacterencoding( string charset ) ;
設置響應使用的字符編碼格式。
22. void setcontentlength( int length ) ;
設置響應的body長度。
23. void setcontenttype( string type ) ;
設置響應的類型。
24. void setdateheader( string name, long value ) ;
設置指定名稱的data類型的http頭的值。
25. void setheader( string name, string value ) ;
設置指定名稱的http頭的值。
26. void setintheader( string name, int value ) ;
設置指定名稱的int類型的http頭的值。
27. void setstatus( int xc ) ;
設置響應狀態碼,新值會覆蓋當前值。
成員(http狀態碼):
int sc_continue = 100 int sc_switching_protocols = 101
int sc_ok = 200 int sc_non_authoritative_information = 203
int sc_accepted = 202 int sc_created = 201
int sc_no_content = 204 int sc_reset_content = 205
int sc_partial_content = 206 int sc_multiple_choices = 300
int sc_moved_permanently = 301 int sc_moved_temporarily = 302
int sc_found = 302 int sc_see_other = 303
int sc_not_modified = 304 int sc_use_proxy = 305
int sc_temporary_redirect = 307 int sc_bad_request = 400
int sc_unauthorized = 401 int sc_payment_required = 402
int sc_forbidden = 403 int sc_not_found = 404
int sc_method_not_allowed = 405 int sc_not_acceptable = 406
int sc_proxy_authentication_required = 407 int sc_request_timeout = 408
int sc_conflict = 409 int sc_gone = 410
int sc_length_required = 411 int sc_precondition_failed = 412
int sc_request_entity_too_large = 413 int sc_request_uri_too_long = 414
int sc_unsupported_media_type = 415 int sc_requested_range_not_satisfiable = 416
int sc_expectation_failed = 417 int sc_internal_server_error = 500
int sc_not_implemented = 501 int sc_bad_gateway = 502
int sc_service_unavailable = 503 int sc_gateway_timeout = 504
int sc_http_version_not_supported = 505
④ session - javax.servlet.http.httpsession
session對象表示目前個別用戶的會話狀態,用來識別每個用戶。
方法:
1. object getattribute( string name ) ;
獲取與指定名字相關聯的session屬性值。
2. enumeration getattributenames() ;
取得session內所有屬性的集合。
3. long getcreationtime() ;
返回session的創建時間,最小單位千分之一秒。
4. string getid() ;
取得session標識。
5. long getlastaccessedtime() ;
返回與當前session相關的客戶端最后一次訪問的時間,由1970-01-01算起,單位毫秒。
6. int getmaxinactiveinterval( int interval ) ;
返回總時間,以秒為單位,表示session的有效時間(session不活動時間)。-1為永不過期。
7. servletcontext getservletcontext() ;
返回一個該jsp頁面對應的servletcontext對象實例。
8. httpsessioncontext getsessioncontext() ;
9. object getvalue( string name ) ;
取得指定名稱的session變量值,不推薦使用。
10. string[] getvaluenames() ;
取得所有session變量的名稱的集合,不推薦使用。
11. void invalidate() ;
銷毀這個session對象。
12. boolean isnew() ;
判斷一個session是否由服務器產生,但是客戶端并沒有使用。
13. void pubvalue( string name, object value ) ;
添加一個session變量,不推薦使用。
14. void removevalue( string name ) ;
移除一個session變量的值,不推薦使用。
15. void setattribute( string name, string value ) ;
設置指定名稱的session屬性值。
16. void setmaxinactiveinterval( int interval ) ;
設置session的有效期。
17. void removeattribute( string name ) ;
移除指定名稱的session屬性。
⑤ pagecontext - javax.servlet.jsp.pagecontext
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 )來取用它的方法和屬性。
新聞熱點
疑難解答