JSP details-other built-in JSP objects

Source: Internet
Author: User

JSP details-other built-in JSP objects
PageContext object

The pageContext () object for obtaining the page context is a special object that can be used to obtain the request, response, session, application, exception, and other objects of the JSP page. The creation and initialization of the pageContext () object are completed by the container. You can directly use the pageContext () object on the JSP page.

1. The pageContext object obtains the session range.

Common Methods for pageContext objects:

Forward (java. lang. String URL): forward the page to another page

GetAttribute (String name): Get the parameter value

GetAttributeNamesInScope (int scope): gets a set of parameter names in a range and returns the Enumeration object.

GetException (): returns the Exception object.

GetRequest (): return the request object

GetResponse (): returns the response object.

GetSession (): returns the session object.

GetOut (): returns the Out object.

GetApplication (): returns the application object.

SetAttribute (): Set the attribute value within the specified range.

RemoveAttribute (): deletes a specified attribute within a specified range.

PageContext objects are rarely used, because request and response are both built-in objects and calling through pageContext is troublesome.

Config object

The cnfig object is used to read web. xml configuration information.

The config object mainly obtains server configuration information, and obtains a config object through the getServletConfig () method of the pageContext object. When a Servlet is initialized, the container passes some information to the Servlet through the config object. Developers can provide initialization parameters for Servlet and JSP pages in the application environment in web. xml.

Common Methods for config objects:

GetServletContext (): Get the Servlet context

GetServletName (): Get the Servlet server name

GetInitParameter (): obtains all the initialization parameters of the server and returns the Enumeration object.

GetInitParameterNames (): Get the initial value of the name parameter in the server

Page Object

The Page Object indicates the JSP itself, which is valid only on the JSP Page. The Page object is essentially a variable that contains the current Servlet excuse reference and can be considered as an alias for the this keyword.

Common Methods for page objects:

GetClass (): returns the class of the current Object

HashCode (): returns the hash code of the Object.

ToString (): converts the Object class to a string.

Equals (): checks whether the object is equal to the specified object.

Exception object

The Exception object is used to handle all exceptions and errors that occur during JSP file execution. Only pages with the isErrorPage attribute set to true in the page command can be used. When this object is used on a page that sets isErrorPage to true, the JSP page cannot be compiled. The Exception object defines almost all exceptions.

Common Methods for Exception objects:

GetMessage (): returns the exception message string of the exception object.

GetLocalizedmessage (): returns localized exception information.

ToString (): returns a brief description of the exception information.

FillInStackTrace (): overwrites the trajectory of stack execution with exceptions.



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.