Detailed description of JSP built-in objects: page, out, exception, config, and pageContext built-in objects

Source: Internet
Author: User

I,

Page built-in object Introduction

The page object is similar to the this pointer in Java programming, that is, the current JSP page itself. Page is the Object of the java. lang. Object Class. Page objects are not frequently used in actual development.

Common page Object Methods

GetClass (): return the class of the current Object.
HashCode (): return the hash code of the Object at this time.
ToString (): Convert the Object class to a string.
Equals (Object ob): Compares whether the Object is equal to the specified Object.
Copy (Object ob): copy the Object to the specified Object.
Clone (): This object is cloned.

II,

Out built-in object Introduction

The out object is used to output data on pages. It is the most frequently used object during JSP development. However, it is easy to use.

Common out object Methods

Print (): print the string information on the page without line breaks.
Print (): print the string information on the page and wrap the line.
Clear (): clear the remaining content in the buffer.
ClearBuffer (): clears the remaining content in the current buffer.
Flush (): clears data streams.
GetBufferSize (): memory size of the returned buffer, in bytes. If you do not set the buffer, the size is 0.
GetRemaining (): the number of bytes remaining in the returned buffer.
IsAutoFlush (): checks whether the current buffer is set to automatically cleared, or throws an exception when it is full.
Close (): close the output stream.
III,

Exception built-in object Introduction

The built-in exception object is used to handle page exception errors. It is an object of the java. lang. Throwable class. During JSP development, it is usually on A page (such as. jsp) to point it to a page (doError. jsp ). If the error processing page is doError. jsp has encapsulated. error message received by the jsp page, and doError on the error handling page. if the isErrorpage attribute contained in jsp is set to true, the error handling page can call the exception built-in object to process the error information.

Common Methods for exception objects

GetMessage () and getLocalizedMessage (): both methods return the exception message string of the exception object and the exception error in the localization language respectively.
PrintStackTrace (): displays abnormal stack tracing traces.
ToString (): return a brief message description about an exception or error.
FillInStackTrace (): overwrite the stack execution track with an exception or error.

IV,

Introduction to built-in config objects

The built-in config object is an instance of the ServletConfig class. It is used by the JSP Engine to transmit information to it (Servlet) through config during Servlet initialization. This information can be a parameter that matches the property name/value, or it can be information about the server passed through the ServletContext object. The built-in config object is rarely used in JSP development. It is used only when the Servlet init () method needs to be reloaded when writing the Servlet.

Common Methods for config objects

GetServletContext (): returns a ServletContext object containing server-related information.
GetIntParameter (String name): return the value of the initialization parameter.
GetIntParameterNames (): returns all parameters required for Servlet initialization. The return type is enumeration.
V,

Introduction to built-in pageContext objects

The pageContext built-in object is a special object, which is equivalent to the largest integrator of all other object functions on the page, that is, it can be used to access all other objects on the page, for example, the previously described request, response, out, and page objects. Since objects such as request and response in JSP can be used directly by calling methods, pageContext objects are rarely used in actual JSP development.
Common Methods for pageContext objects

GetRequest (): returns the request object on the current page.
GetResponse (): returns the response object on the current page.
GetSession (): returns the session object on the current page.
GetServletContext (): returns the application object on the current page.
GetPage (): returns the page object on the current page.
GetOut (): returns the out object on the current page.
GetException (): returns the exception object on the current page.
GetServletConfig (): returns the config object on the current page.
Www.2cto.com
SetAttribute (String name): Set the attribute value for the specified attribute name.
GetAttribute (String naem): locate the attribute value based on the attribute name.
SetAttribute (String name, Object obj, int scope): Set the attribute value within the specified range.
GetAttribute (String name, int scope): Get the corresponding attribute value within the given range.
FindAttribute (String name): searches for an attribute and returns it. If it cannot be found, null is returned.
RemoveAttribute (String name): deletes an attribute by its name.
RemoveAttribute (String name, int scope): deletes an attribute in a specified range.
GetAttributeScope (String name scope): returns the scope of an attribute.
GetAttributeNamesInScope (int scope): returns the enumeration of all attribute names in the specified range.

Release (): releases all data occupied by pageContext.
Forward (String relativeURLpath): use the current page to re-export to another page.
Include (String relativeURLpath): use another page contained in the current position.

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.