This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
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
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>
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
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.