Methods of pageContext Implicit Object

Object findAttribute (String AttributeName): This method searches for the specified attribute in all four levels in the following order – Page, Request, Session and Application. It returns NULL when no attribute found at any of the level.

Object getAttribute (String AttributeName, int Scope): It looks for an attribute in the specified scope. This method is similar to findAttribute method; the only difference is that findAttribute looks in all the four levels in a sequential order while getAttribute looks in a specified scope. For e.g. – In the below statement the getAttribute method would search for the attribute “BeginnersBook” in Session scope (or Session level/layer). If it finds the attribute it would assign it to Object obj else it would return Null.

void removeAttribute(String AttributeName, int Scope): This method is used to remove an attribute from a given scope. For example – The below JSP statement would remove an Attribute “MyAttr” from page scope.

pageContext.removeAttribute(“MyAttr”, PageContext. PAGE_CONTEXT);

void setAttribute(String AttributeName, Object AttributeValue, int Scope): It writes an attribute in a given scope. Example – Below statement would store an Attribute “mydata” in application scope with the value “This is my data”.

In this page we are storing user’s credentials using pageContext implicit object with the session scope, which means we will be able to access the details till the user’s session is active. We can also store the attribute using other scope parameters such as page, application and request.

In this JSP page we are fetching the stored attributes using getAttribute method. The point to note here is that we have stored the attributes with session scope so we must need to specify scope as session in order to fetch those attribute’s value.

User Credentials display page which we have passed from login page to this page through pageContext instance.
If you have any questions regarding pageContext implicit object, feel free to ask by dropping a comment below. We will be more than happy to assist you!!