aspose file tools*
The moose likes Servlets and the fly likes Difference between pageContext. getAttribute() and getParameter () Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Difference between pageContext. getAttribute() and getParameter ()" Watch "Difference between pageContext. getAttribute() and getParameter ()" New topic
Author

Difference between pageContext. getAttribute() and getParameter ()

Doshi Milan
Ranch Hand

Joined: May 29, 2001
Posts: 112
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

Joined: May 24, 2001
Posts: 245
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.


chanoch<p><a href="http://www.amazon.com/exec/obidos/ASIN/1861007736/" target="_blank" rel="nofollow">Author of Professional Apache Tomcat</a></p>
Jo Lee
Ranch Hand

Joined: Jun 26, 2001
Posts: 35
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

Joined: Feb 20, 2001
Posts: 580
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.


James Carman, President<br />Carman Consulting, Inc.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Difference between pageContext. getAttribute() and getParameter ()