| Author |
Life of an attribute
|
Adam Zedan
Ranch Hand
Joined: Jun 10, 2011
Posts: 124
|
|
Hi i wanted to know about the life of an attribute , suppose we go like
request.setAttribute("Name","Value");
or
servletcontext.setAttriute("Name","Value");
or
session.setAttribute("Name","Value");
Now i wanted to know when will these values remain ..
Consider the following scenario:
First Request:
User Request ->Container->Servlet (The servlet inserts attributes using any of above method)->Send response back to container (which sends it to the user)
Now suppose the user makes a second request repeating the above cycle my question is will the attributes which i had inserted in the first cycle be available to the servlet or are all the attributes of the order and context cleared everytime a fresh request comes in ??
My question is will the att
|
Don’t look where you fall, but where you slipped
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56529
|
|
All these question can be answered by looking through the Servlet Spec, or trying it yourself.
But in brief, scoped variables place in a request last for the lifetime of the request. Those placed in the session last for the lifetime of the session. And those placed in application context last the lifetime of the application.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Suhas Mandrawadkar
Ranch Hand
Joined: Jul 21, 2007
Posts: 72
|
|
request.setAttribute("Name","Value"); <- this will be lost as soon as you are done with your request, that is after sending back the response.
Request attribute will be alive as long as that request is being processed (in your example first request).
session.setAttribute("Name","Value"); <- this will be lost after you are done with your session. Generally spans several requests.
servletcontext.setAttriute("Name","Value"); <- this will be lost when you undeploy your web app.
|
Regards, Suhas S. Mandrawadkar.
Certifications: SCJP 6, SCWCD 5, Oracle WebLogic Server Administrator, OCE Java EE 6 EJB Developer
|
 |
Adam Zedan
Ranch Hand
Joined: Jun 10, 2011
Posts: 124
|
|
Suhas Mandrawadkar wrote:request.setAttribute("Name","Value"); <- this will be lost as soon as you are done with your request, that is after sending back the response.
Request attribute will be alive as long as that request is being processed (in your example first request).
session.setAttribute("Name","Value"); <- this will be lost after you are done with your session. Generally spans several requests.
servletcontext.setAttriute("Name","Value"); <- this will be lost when you undeploy your web app.
Thanks for the great explination... couldnt expect a better one...
|
 |
 |
|
|
subject: Life of an attribute
|
|
|