Nine built-in JSP objects [Details]

Source: Internet
Author: User

① Out-javax. servlet. jsp. jspwriter <br/> The out object is used to output the result to the webpage. </P> <p> method: <br/> 1. Void clear (); <br/> clear the content of the output buffer, but not output to the client. </P> <p> 2. Void clearbuffer (); <br/> clear the content of the output buffer and output it to the client. </P> <p> 3. Void close (); <br/> close the output stream and clear all content. </P> <p> 4. Void flush (); <br/> output data in the buffer. </P> <p> 5. Int getbuffersize (); <br/> obtains the current buffer size in KB. </P> <p> 6. Int getremaining (); <br/> obtains the unoccupied space in the buffer in KB. </P> <p> 7. boolean isautoflush (); <br/> whether to automatically refresh the buffer. </P> <p> 8. Void newline (); <br/> output a line feed character. </P> <p> 9. void print (Boolean B); <br/> void print (char C); <br/> void print (char [] S ); <br/> void print (double D); <br/> void print (float F); <br/> void print (int I ); <br/> void print (long l); <br/> void print (Object OBJ); <br/> void print (string S ); <br/> output data of the specified type to the HTTP stream without line breaks. </P> <p> 10. void println (Boolean B); <br/> void println (char C); <br/> void println (char [] S ); <br/> void println (double D); <br/> void println (float F); <br/> void println (int I ); <br/> void println (long l); <br/> void println (Object OBJ); <br/> void println (string S ); <br/> output data of the specified type to the HTTP stream and a line break. </P> <p> 11. appendable append (char C); <br/> appendable append (charsequence cxq, int start, int end); <br/> appendable append (charsequence cxq ); <br/> Add a character or an object that implements the charsequence interface to the end of the output stream. </P> <p> member: <br/> int default_buffer = 0-default buffer size <br/> int no_buffer =-1-whether the writer is in the buffer output state <br/> int unbounded_buffer =-2-whether to limit buffer size </P> <p> ② request-javax. servlet. HTTP. httpservletrequest <br/> the request object contains information about all requests, such as the request source, header, cookies, and request-related parameter values. </P> <p> method: <br/> 1. Object getattribute (string name); <br/> return the property value specified by name. If the property does not exist, null is returned. </P> <p> 2. Enumeration getattributenames (); <br/> return a set of all attribute names of the request object. </P> <p> 3. String getauthtype (); <br/> return the name of the authentication method used to protect the servlet. If not, null is returned. </P> <p> 4. String getcharacterencoding (); <br/> return the character encoding method in the request, which can be set in the response object. </P> <p> 5. Int getcontentlength (); <br/> return the length of the Request body. If the length cannot be determined, return-1. You can set it in response. </P> <p> 6. String getcontenttype (); <br/> return the content type defined in response. </P> <p> 7. String getcontentpath (); <br/> return the Request Path. </P> <p> 8. Cookie [] getcookies (); <br/> return an array of all cookies on the client. </P> <p> 9. Enumeration getheadernames (); <br/> Returns a set of names of all HTTP headers. </P> <p> 10. Enumeration getheaders (string name); <br/> return a set of all values of the specified HTTP header. </P> <p> 11. String getheader (string name); <br/> the HTTP header with the specified name is returned. </P> <p> 12. Long getdateheader (string name); <br/> return the information of the data-Type HTTP header with the specified name. </P> <p> 13. Int getintheader (string name); <br/> return the information of the HTTP header of the int type with the specified name. </P> <p> 14. servletinputstream getinputstream (); <br/> return the input stream of the request. </P> <p> 15. locale getlocale (); <br/> return the locale object of the current page, which can be set in response. </P> <p> 16. Enumeration getlocales (); <br/> return the set of all locale objects in the request. </P> <p> 17. String getlocalname (); <br/> obtain the server host name in response to the request. </P> <p> 18. String getlocaladdr (); <br/> obtain the server address of the Response Request. </P> <p> 19. int getlocalport (); <br/> get the server port responding to the request </P> <p> 20. string getmethod (); <br/> obtain the methods (get and post) that the client sends a request to the server ). </P> <p> 21. String getparameter (string name); <br/> obtain the parameter value sent from the client to the server. </P> <p> 22. Map getparametermap (); <br/> This method returns a map object containing all the parameters in the request. </P> <p> 23. Enumeration getparameternames (); <br/> return a set of all parameters in the request. </P> <p> 24. String [] getparametervalues (string name); <br/> obtain all values of the specified parameter in the request. </P> <p> 25. String getquerystring (); <br/> return the parameter string passed by the get method. This method does not parse individual parameters. </P> <p> 26. String getpathinfo (); <br/> retrieve the additional information in the request between servletpath and querystring. </P> <p> 27. String getpathtranslated (); <br/> return the actual path of the path information obtained using the getpathinfo () method. </P> <p> 28. String getprotocol (); <br/> return the protocol used by the request. It can be http1.1 or http1.0. </P> <p> 29. bufferedreader getreader (); <br/> the reader object corresponding to the input stream of the request is returned. This method and the getinputstream () method can only be called on one page. </P> <p> 30. String getremoteaddr (); <br/> obtain the IP address of the client sending the request. </P> <p> 31. string getremotehost (); <br/> obtain the client host name that sends the request </P> <p> 32. string getremoteuser (); <br/> the user name verified by the client is returned. If the user name is not verified, null is returned. </P> <p> 33. Int getremoteport (); <br/> return the client host port sending the request. </P> <p> 34. String getrealpath (string path); <br/> returns the physical path of the given virtual path. </P> <p> 35. requestdispatcher getrequestdispatcher (string path); <br/> Generate a resource based on the given path to process the adapter object. </P> <p> 36. String getrequestedsessionid (); <br/> return the ID of the Request session. </P> <p> 37. String requesturi (); <br/> return the client address that sends the request, but does not include the request parameter string. </P> <p> 38. stringbuffer getrequesturi (); <br/> return the server address of the Response Request </P> <p> 39. string getscheme (); <br/> obtain the protocol name. The default value is HTTP. </P> <p> 40. String getservername (); <br/> return the name of the server responding to the request. </P> <p> 41. String getservletpath (); <br/> obtain the path of the script file requested by the client. </P> <p> 42. Int getserverport (); <br/> obtain the server host port number that responds to the request. </P> <p> 43. Void removeattribute (string name); <br/> Delete the attribute of the specified name in the attribute list. </P> <p> 44. Void setattribute (string name, object value); <br/> Add/delete a specified attribute in the attribute list. </P> <p> 45. Void setcharacterencoding (string name); <br/> set the character encoding format of the request. </P> <p> 46. httpsession getsession (); <br/> httpsession getsession (Boolean create); <br/> get the session. If create is set to true, create a session without a session. </P> <p> 47. boolean isrequestedsessionidfromcookie (); <br/> check whether the request session ID is passed through cookies. </P> <p> 48. boolean isrequestedsessionidfromurl (); <br/> check whether the request session ID is passed through a URL. </P> <p> 49. boolean isrequestedsessionidvalid (); <br/> check whether the request session ID is still valid. </P> <p> 50. boolean issecure (); <br/> check whether the request uses a secure link, if https or so. </P> <p> 51. boolean isuserinrole (string role); <br/> check whether the verified user is in the role specified by role. </P> <p> 52. Principal getuserprincipal (); <br/> A java. Security. principal object containing the user's login name is returned. </P> <p> member: <br/> string basic_auth = "Basic"-<br/> string client_cert_auth = "client_cert"-<br/> string digest_auth = "Digest"-<br/> string form_auth = "form"-</P> <p> ③ response-javax. servlet. HTTP. httpservletresponse <br/> the response object mainly transmits the results processed by the JSP Container Back to the client. </P> <p> method: <br/> 1. Void addcookie (cookie); <br/> Add a cookie object to save client information. </P> <p> 2. Void adddateheader (string name, long value); <br/> Add a date-Type HTTP header that overwrites the HTTP header with the same name. </P> <p> 3. Void addheader (string name, string value); <br/> Add an HTTP header to overwrite the old HTTP header with the same name. </P> <p> 4. Void addintheader (string name, int value); <br/> Add an integer HTTP header to overwrite the old HTTP header with the same name. </P> <p> 5. boolean containsheader (string name); <br/> determine whether the specified HTTP header exists. </P> <p> 6. String encoderedirecturl (string URL); <br/> encode the URL used by sendredirect. </P> <p> 7. String encodeurl (string URL); <br/> encode the URL and return the URL containing the session ID. </P> <p> 8. Void flushbuffer (); <br/> force the content of the current buffer zone to be sent to the client. </P> <p> 9. Int getbuffersize (); <br/> obtain the buffer size in KB. </P> <p> 10. String getcharacterencoding (); <br/> obtain the character encoding format of the response. </P> <p> 11. String getcontenttype (); <br/> obtain the response type. </P> <p> 12. locale getlocale (); <br/> obtain the response locale object. </P> <p> 13. servletoutputstream getoutputstream (); <br/> return the output stream object of the client. </P> <p> 14. printwriter getwriter (); <br/> obtain the writer object corresponding to the output stream. </P> <p> 15. boolean iscommitted (); <br/> determine whether the server has output data to the client. </P> <p> 16. Void reset (); <br/> clear all content in the buffer. </P> <p> 17. Void resetbuffer (); <br/> all content in the buffer, but the HTTP header and status information are retained. </P> <p> 18. void senderror (int xc, string MSG); <br/> void senderror (int xc); <br/> sending error, including status code and error message. </P> <p> 19. Void sendredirect (string locationg); <br/> send the response to another location for processing. </P> <p> 20. Void setbuffersize (INT size); <br/> set the buffer size in KB. </P> <p> 21. Void setcharacterencoding (string charset); <br/> set the character encoding format used by the response. </P> <p> 22. Void setcontentlength (INT length); <br/> set the length of the response body. </P> <p> 23. Void setcontenttype (string type); <br/> set the response type. </P> <p> 24. Void setdateheader (string name, long value); <br/> set the value of the HTTP header of the data type with the specified name. </P> <p> 25. Void setheader (string name, string value); <br/> set the HTTP header value of the specified name. </P> <p> 26. Void setintheader (string name, int value); <br/> set the HTTP header value of the int type of the specified name. </P> <p> 27. Void setstatus (int xc); <br/> set the response status code. The new value overwrites the current value. </P> <p> member (HTTP status code ): <br/> int SC _continue = 100 int SC _switching_protocols = 101 <br/> int SC _ OK = 200 int SC _non_authoritative_information = 203 <br/> int SC _accepted = 202 int SC _created = 201 <br/> int SC _no_content = 204 int SC _reset_content = 205 <br/> int SC _partial_content = 206 int SC _multiple_choices = 300 <br/> int Limit = 301 int Limit = 302 <br/> int SC _found = 30 2 int SC _see_other = 303 <br/> int SC _not_modified = 304 int SC _use_proxy = 305 <br/> int response = 307 int SC _bad_request = 400 <br/> int SC _unauthorized = 401 int response = 402 <br/> int SC _forbidden = 403 int SC _not_found = 404 <br/> int SC _method_not_allowed = 405 int SC _not_acceptable = 406 <br/> int Limit = 407 int SC _request_timeout = 408 <br/> Int SC _conflict = 409 int SC _gone = 410 <br/> int SC _length_required = 411 int SC _precondition_failed = 412 <br/> int Limit = 413 int Limit = 414 <br/> int Limit = 415 int SC _requested_range_not_satisfiable = 416 <br/> int SC _expectation_failed = 417 int SC _internal_server_error = 500 <br/> int SC _not_implemented = 501 int SC _bad_gateway = 502 <Br/> int SC _service_unavailable = 503 int SC _gateway_timeout = 504 <br/> int SC _http_version_not_supported = 505 </P> <p> ④ session-javax. servlet. HTTP. httpsession <br/> the session object indicates the session Status of individual users, which is used to identify each user. </P> <p> method: <br/> 1. Object getattribute (string name); <br/> obtain the session attribute value associated with the specified name. </P> <p> 2. Enumeration getattributenames (); <br/> obtains the set of all attributes in the session. </P> <p> 3. Long getcreationtime (); <br/> return the session creation time. The minimum unit is 1‰ seconds. </P> <p> 4. String GETID (); <br/> obtain the session ID. </P> <p> 5. Long getlastaccessedtime (); <br/> return the last access time of the client associated with the current session, counted from, in milliseconds. </P> <p> 6. Int getmaxinactiveinterval (INT interval); <br/> the total returned time, in seconds, indicates the session validity period (the session is not active ). -1 indicates that it never expires. </P> <p> 7. servletcontext getservletcontext (); <br/> an instance of the servletcontext object corresponding to the JSP page is returned. </P> <p> 8. httpsessioncontext getsessioncontext (); </P> <p> 9. object getvalue (string name); <br/> get the session variable value of the specified name, which is not recommended. </P> <p> 10. String [] getvaluenames (); <br/> the set of names of all session variables is not recommended. </P> <p> 11. Void invalidate (); <br/> destroy the session object. </P> <p> 12. boolean isnew (); <br/> checks whether a session is generated by the server, but is not used by the client. </P> <p> 13. Void pubvalue (string name, object value); <br/> it is not recommended to add a session variable. </P> <p> 14. Void removevalue (string name); <br/> it is not recommended to remove the value of a session variable. </P> <p> 15. Void setattribute (string name, string value); <br/> set the session attribute value of the specified name. </P> <p> 16. Void setmaxinactiveinterval (INT interval); <br/> set the session validity period. </P> <p> 17. Void removeattribute (string name); <br/> remove the session attribute of the specified name. </P> <p> ⑤ pagecontext-javax. servlet. jsp. pagecontext <br/> the pagecontext object stores information about the JSP page, such as attributes and built-in objects. </P> <p> method: <br/> 1. void setattribute (string name, object value, int scope); <br/> void setattribute (string name, object value); <br/> set attributes within the specified sharing range. </P> <p> 2. object getattribute (string name, int scope); <br/> Object getattribute (string name); <br/> get the attribute value named name in the specified shared range. </P> <p> 3. Object findattribute (string name); <br/> Search for named properties by PAGE, request, session, and application sharing range. </P> <p> 4. void removeattribute (string name, int scope); <br/> void removeattribute (string name); <br/> remove attributes with the specified name and shared range. </P> <p> 5. Void forward (string URL); <br/> navigate the page to the specified URL. </P> <p> 6. Enumeration getattributenamesscope (INT scope); <br/> obtains a set of all attribute names within the specified shared range. </P> <p> 7. Int getattributescope (string name); <br/> get the sharing range of the specified attribute. </P> <p> 8. errordata geterrordate (); <br/> get the errordata object on the page. </P> <p> 9. Exception getexception (); <br/> get the exception object of the page. </P> <p> 10. expressionevaluator getexpressionevaluator (); <br/> obtain the expressionevaluator object on the page. </P> <p> 11. jspwriter getout (); <br/> get the out object of the page. </P> <p> 12. Object getpage (); <br/> obtain the Page Object of the page. </P> <p> 13. servletrequest getrequest (); <br/> obtain the request object on the page. </P> <p> 14. servletresponse getresponse (); <br/> get the page's response object. </P> <p> 15. servletconfig getconfig (); <br/> get the config object of the page. </P> <p> 16. servletcontext getservletcontext (); <br/> obtain the servletcontext object of the page. </P> <p> 17. httpsession getsession (); <br/> obtain the session object on the page. </P> <p> 18. variableresolver getvariableresolver (); <br/> obtain the variableresolver object on the page. </P> <p> 19. void include (string URL, Boolean flush); <br/> void include (string URL); <br/> includes other resources and specifies whether to automatically refresh. </P> <p> 20. Void release (); <br/> Reset the internal status of pagecontext and release all internal references. </P> <p> 21. void initialize (servlet, servletrequest request, servletresponse response, <br/> string errorpageurl, Boolean needsession, int buffersize, Boolean autoflush); <br/> initialize uninitialized pagecontext objects. </P> <p> 22. bodycontext pushbody (); <br/> bodycontext pushbody (writer); <br/> saves the current out object and updates the out object in the page range of pagecontext. </P> <p> 23. jspwrite popbody (); <br/> retrieve the out object saved by the pushbody () method. </P> <p> 24. void handlepageexception (exception E); <br/> void handlepageexception (thrwoable T); </P> <p> member: <br/> int page_scope = 1-page sharing range <br/> int request_scope = 2-request sharing range <br/> int session_scope = 3-session sharing range <br/> int application_scope = 4-application sharing scope <br/> string page = "javax. servlet. JSP. jsppage "<br/> string pagecontext =" javax. servlet. JSP. jsppagecontext "<br/> string request =" javax. servle T. JSP. jsprequest "<br/> string response =" javax. servlet. JSP. jspresponse "<br/> string Config =" javax. servlet. JSP. jspconfig "<br/> string session =" javax. servlet. JSP. jspsession "<br/> string out =" javax. servlet. JSP. jspout "<br/> string application =" javax. servlet. JSP. jspapplication "<br/> string exception =" javax. servlet. JSP. jspexception "</P> <p> ⑥ application-javax. servlet. servletcontext <br/> app Lication is mainly used to get or change servlet settings. </P> <p> method: <br/> 1. Object getattribute (string name); <br/> the application attribute specified by name is returned. </P> <p> 2. Enumeration getattributes (); <br/> all application attributes are returned. </P> <p> 3. servletcontext getcontext (string uripath); <br/> obtain the servletcontext object of the current application. </P> <p> 4. String getinitparameter (string name); <br/> return the initial value of the application attribute specified by name. </P> <p> 5. Enumeration getinitparameters (); <br/> return the set of initial values of all application attributes. </P> <p> 6. Int getmajorversion (); <br/> the version number of the servlet API supported by the servlet container is returned. </P> <p> 7. String getmimetype (string file); <br/> the type of the specified file is returned. If the file type is unknown, null is returned. It is generally "text/html" and "image/GIF ". </P> <p> 8. Int getminorversion (); <br/> the minor version of the servlet API supported by the servlet container is returned. </P> <p> 9. String getrealpath (string path); <br/> returns the physical path corresponding to the given virtual path. </P> <p> 10. requestdispatcher getnameddispatcher (string name); <br/> an instance of the requestdispatcher object is returned for the servlet object with the specified name. </P> <p> 11. requestdispatcher getrequestdispatcher (string path); <br/> an instance of the requestdispatcher object is returned. </P> <p> 12. url getresource (string path); <br/> return a URL object instance corresponding to the specified resource path. The parameter must start. </P> <p> 13. inputstream getresourceasstream (string path); <br/> Returns An inputstream object instance of the resource at the specified position of the path. </P> <p> 14. Set getresourcepaths (string path); <br/> return the set of all resource paths stored in the Web-app. </P> <p> 15. String getserverinfo (); <br/> obtain the application server version. </P> <p> 16. servlet getservlet (string name); <br/> retrieve the servlet with the specified name in servletcontext. </P> <p> 17. Enumeration getservlets (); <br/> return the set of all servlets in servletcontext. </P> <p> 18. String getservletcontextname (); <br/> return the name of the Web application. </P> <p> 19. Enumeration getservletcontextnames (); <br/> return the name set of all servlets in servletcontext. </P> <p> 20. void log (exception ex, string MSG); <br/> void log (string MSG, throwable T); <br/> void log (string MSG ); <br/> write the specified information to the servlet log file. </P> <p> 21. Void removeattribute (string name); <br/> remove the application attribute of the specified name. </P> <p> 22. Void setattribute (string name, object value); <br/> set the value of the specified application attribute. </P> <p> 7config-javax. servlet. servletconfig <br/> the config object is used to store the initial servlet data structure. </P> <p> method: <br/> 1. String getinitparameter (string name); <br/> return the value of the parameter promoted by name. </P> <p> 2. Enumeration getinitparameters (); <br/> return a set of names of all the prompt parameters in the JSP. </P> <p> 3. servletcontext getcontext (); <br/> the servlet context of the performer is returned. </P> <p> 4. String getservletname (); <br/> the servlet name is returned. </P> <p> Except exception-java. lang. throwable <br/> error object. The exception object can be used on this page only after iserrorpage = "true" is specified in the page command of the JSP page. </P> <p> method: <br/> 1. throwable fillinstacktrace (); <br/> record the current stack information to the exception object. </P> <p> 2. String getlocalizedmessage (); <br/> obtain the error message of the local language. </P> <p> 3. String getmessage () <br/> get the error message. </P> <p> 4. stacktrackelement [] getstacktrace (); <br/> return the call stack track information recorded in the object. </P> <p> 5. throwable initcause (throwable cause); <br/> nest another exception object into the current exception object. </P> <p> 6. throwable getcause (); <br/> retrieve exceptions nested in the current exception object. </P> <p> 7. void printstacktrace (); <br/> void printstacktrace (printstream S); <br/> void printstacktrace (printwriter S); <br/> prints throwable and its call stack trace information. </P> <p> 8. Void setstacktrace (stacktraceelement [] stacktrace) <br/> sets the call stack trace information of an object. </P> <p> analyze page-javax. servlet. JSP. httpjsppage <br/> the Page Object represents the JSP object itself, or the compiled servlet object. <br/> it can be used (javax. servlet. JSP. httpjsppage) page.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.