pagecontext

is mainly used for get/set/remove the value from the pageConext instance of class PageContext. We do not need to create this instance as it is created by the container it self for us.

The pageContext comes with flexibility where you can specify scope explicitly for each stored entity.

Scopes for the entity which is saved in pageContext are

page

-the value stored with page scope can be used in the same page

request

-the value used in the request can be used in the same request quantum.

session

-the value set with scope session can be used in the same session.

application

-value set with scope application can be used anywhere as it is global scope.

In very simple words page and request scope variables can be accessed in the same page whereas the application and session scope variables can be accessed in the other pages also.

How to set pageContext

pageContext.jsp

How to get pageContext

pageContextDemo.jsp

Run pageContext.jsp
You can see values of request and page level scopes.
Now click the hyperlink
You can see values of session and application.

So we conclude that session and application scopes should be used when you need variable to be accessed across different jsp pages.

Leave a Reply

Your email address will not be published. Required fields are marked *