Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

what's the difference between the methods pageContext.findAttribute() and session.getAttribute()?  RSS feed

 
changyu ji
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if i've stored the "cart" attribute in session,
what's the difference between the methods pageContext.findAttribute("cart") and session.getAttribute("cart") in servlet file,
do they have the same function in this case?
 
Paul Ngom
Ranch Hand
Posts: 355
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

what's the difference between the methods pageContext.findAttribute("cart") and session.getAttribute("cart") in servlet file,
do they have the same function in this case?

As you might have noticed, you are using 2 different scopes namely page and session.
PageContext.findAttribute("cart") will search successively: page, request, session and application scopes
and return the associated value with 'cart' if found or null. Whereas session.getAttribute("cart") will search only the session scope
and return the value associated with 'cart' or null.
Therefore, if you have previously stored the 'cart' object in session,
these methods will basically return the same value.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!