JSP内置对象
发布时间:2023-05-16 13:28:49 所属栏目:教程 来源:
导读:JSP内建对象
① out - javax.servlet.jsp.jspwriter
out对象用于把结果输出到网页上。
方法:
1. void clear() ;
清除输出缓冲区的内容,但是不输出到客户端。
2. void clearbuffer()
① out - javax.servlet.jsp.jspwriter
out对象用于把结果输出到网页上。
方法:
1. void clear() ;
清除输出缓冲区的内容,但是不输出到客户端。
2. void clearbuffer()
JSP内建对象 ① 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。可以在response中设置。 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() ; 返回请求使用的协议。可以是http1.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 )来取用它的方法和属性。 (编辑:聊城站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
站长推荐