File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes session.setAttribute vs request.setAttribute Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "session.setAttribute vs request.setAttribute" Watch "session.setAttribute vs request.setAttribute" New topic

session.setAttribute vs request.setAttribute

Nelson Nadal
Ranch Hand

Joined: Jun 06, 2002
Posts: 170
Just a clarification :-). Im just confuzed what and to when to use those 2 the same method.....
Correct me if Im wrong...
They have the same objective (to keep a certain value)but the difference is the scope of their attribute values? Am I right? I Thanks.
Andy Bowes
Ranch Hand

Joined: Jan 14, 2003
Posts: 171
The basic difference between these 2 methods is the scope or lifetime of the attribute you are setting.
If you set an attribute on the request it is only available for that specific request. If you set it on the session it is available for that request and all subsequent requests by the user using the session (i.e. until the session expires or you explicitly remove the attribute)

Andy Bowes<br />SCJP, SCWCD<br />I like deadlines, I love the whoosing noise they make as they go flying past - Douglas Adams
I agree. Here's the link:
subject: session.setAttribute vs request.setAttribute
It's not a secret anymore!