This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes Stupid question - Request scope vs Session scope Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Stupid question - Request scope vs Session scope" Watch "Stupid question - Request scope vs Session scope" New topic
Author

Stupid question - Request scope vs Session scope

Rick Beaver
Ranch Hand

Joined: Dec 14, 2004
Posts: 464
Hello All

Stupid question. Am I right in assuming that there is little difference in the amount of data transfered over the network for objects stored in request scope, accessed in a JSP, vs objects stored in Session scope accessed the same way?

The objects are just stored in the same way right? The reference client side to a request attribute and a session attribute is the same?

The reason for asking is that someone at work today stated they were moving a map of objects to session scope instead of accessing them through request attributes to reduce network traffic - am I missing something that I should know here?

Thanks


ph34r my 133t j4v4 h4><0r1ng sk177z
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60800
    
  65

Originally posted by Rick Beaver:
Am I right in assuming that there is little difference in the amount of data transfered over the network for objects stored in request scope, accessed in a JSP, vs objects stored in Session scope accessed the same way?


There is no difference because there is no data transferred over the network in either case. And zero is pertty close to zero. The variable scopes are completely server-side mechanisms.


The objects are just stored in the same way right? The reference client side to a request attribute and a session attribute is the same?


There is no client-side reference to either.


The reason for asking is that someone at work today stated they were moving a map of objects to session scope instead of accessing them through request attributes to reduce network traffic - am I missing something that I should know here?


He's confused and making a major blunder if he's moving data to session scope for any reason other than making it available across multiple requests. He's probably just creating a memory leak.
[ April 13, 2006: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Rick Beaver
Ranch Hand

Joined: Dec 14, 2004
Posts: 464
Thanks Bear, I didn't want to correct the chap because I started to doubt myself when he said that...
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Actually it's possible that if you put an object into session scope, the container might serialize it to a database (if you configured persistent sessions into the container). And your database might well be on a different machine. So that would actually INCREASE the network traffic, rather than decreasing it.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Paul Clapham:
Actually it's possible that if you put an object into session scope, the container might serialize it to a database (if you configured persistent sessions into the container). And your database might well be on a different machine. So that would actually INCREASE the network traffic, rather than decreasing it.


In addition, if you're clustering your app servers with session replication.
Every change to the session object will result in it being serialized and synced with the sessions in the other nodes.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Stupid question - Request scope vs Session scope
 
Similar Threads
page scope
setting attributes to session vs. to request
parameter vs attributes?
getAttribute vs getParameter
sendRedirect Vs requestdispatcher.forward