Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Difference between pageContext. getAttribute() and getParameter ()

 
Doshi Milan
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello friends,
I would want to know what is the differnce between
pageContext.getRequest().getParameter("someValue")
and
pageContext.getAttribute("someValue").
Ofcourse they are not the same (... I realised it accidently due to some error ...).Actually I am invoking an EventHandler (i.e a servlet ) through a link something like this:
<A href="/someServlet?someValue='Hello'"...>
I thought that pageContext.getAttribute would retrieve this value but it does not!.
So please guide me with the difference and also if someone can mention URLs wherein I can get some inDepth knowledge about pageContext.(Web articles are usually very basic)
Thanks and regards,
Milan Doshi
 
chanoch wiggers
Author
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
attributes are objects that you store in the request, page, session or application scope. They are a mechanism for java code to pass values around.
Parameters, or "Request parameters" are values that are passed as part of the GET (?name=value) or POST (form variables) requests.
 
Jo Lee
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am now a bit confused about this as well. So in order to use the pageContext.getAttribute("something"); in some other pages, we have to use pageContext.setAttribute() first in order for it to be retrievable. How is this differ from session.setAttribute() besides the scope difference?
Jo
 
James Carman
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jo Lee:
I am now a bit confused about this as well. So in order to use the pageContext.getAttribute("something"); in some other pages, we have to use pageContext.setAttribute() first in order for it to be retrievable. How is this differ from session.setAttribute() besides the scope difference?
Jo

That's exactly it, the scope! If you place an attribute on the session, it will stay there while the session is alive. If you put it on the page context, it is only valid during the execution of that page. If you put it in request scope, it is only valid for the processing of that entire request. If you put it in application scope (via ServletContext.setAttribute method), it is valid for the life of the entire application.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic