Reputation: 9
If I've set "cart" as a session attribute, then what's the difference between the methods pageContext.findAttribute("cart")
and session.getAttribute("cart")
in servlet file ?
Do they do the same thing in this case?
Upvotes: 0
Views: 645
Reputation: 1
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.
session.getAttribute("cart"): This method searches for the specified attribute in only Session scope.
Do they do the same thing in this case? => They do same thing in this case if you dont have attribute name cart in Page, Request.
Upvotes: 0
Reputation: 16660
Was it really too much effort to read the Javadoc for PageContext.findAttribute()?
The PageContext
looks in multiple scopes for the attribute (page, request, session then application) whereas the session.getAttribute()
only looks in the session. If you know the attribute is in the session, then session.getAttribute()
should be (marginally) faster.
Upvotes: 1