Explain the different scopes an object can have in a JSP page.The scope of JSP objects is divided into four parts. They are:
1. Page: Page scope means the object can be accessed within the page only on which it is created. The data is valid only during the processing of the current response; once the response is sent back to the browser, the data is no longer valid. If the request is forwarded to another page or the browser makes another request as a result of a redirect, the data is also lost.
2. Request: The object with request scope means they can be accessed by any page that serves same request. Once the container has processed the request, the data is released. Even if the request is forwarded to another page, the data is still available though not if a redirect is required.
3. Session: This scope means, the JSP object is accessible from pages that belong to the same session from where it was created. For example, when users log in, their username could be stored in the session and displayed on every page they access. This data lasts until they leave the Web site or log out.
4. Application: A JSP object created using the ‘application’ scope can be accessed from any pages across the application. Application scope variables are typically created and populated when an application starts and then used as read-only for the rest of the application.