• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Difference between pageContext. getAttribute() and getParameter ()

 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Author
Posts: 245
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic