PageContext
A PageContext instance provides access to all the namespaces associated with a JSP page, provides access to several page attributes, as well as a layer above the implementation details. Implicit objects are added to the pageContext automatically.
session
Provides a way to identify a user across more than one page request or visit to a Web site and to store information about that user.
PageContext has a set of attributes that are different from the Session object.
The attributes set on PageContext are only available for a given page. The attributes are not available to other pages or servlets in the application.
Session attributes are created per each user's session. The session attributes are unique to a given session id. Session attributes are available to other pages and servlets in the application for a given session id.
Note:
- The PageContext is implicitly instantiated by the application server.
- The JSP page will always have access to the PageContext.
- Session would be expired after 30 minutes when idle or closed the browser.
Reference:
https://tomcat.apache.org/tomcat-8.0-doc/jspapi/javax/servlet/jsp/PageContext.html
https://tomcat.apache.org/tomcat-8.0-doc/servletapi/javax/servlet/http/HttpSession.html