session scope vs request scope
843838Mar 11 2006 — edited Mar 12 2006When is it appropriate to use request scope and session scope? Here is how I understand the two scopes.
-Request scope is used when the data presented to the user is only needed once. Usually something very simple such as login page with username and password.
-Session scope is used when the data presented to the user is used on several pages. Usually something involved such as edit, save, delete, and confirm that spans over several pages with large number of input fields, drop down lists, and display values that you don't want to grab from the database every time you process the page.
Is my understanding of the two scopes correct?
My coworkers have told me that it's better to always use the request scope and always grab the data from the database for every action. I've been told that using session scope is bad because it decreases the performance of your application server when there are large number of users.
I agree with my coworkers to a certain degree. For instance, I believe you should use the request scope when the action is simple, but not for everything. For instance, I feel session scope should be used when you need to retrieve and display data that is used on multiple pages.
Please correct me if I'm wrong, but I find my coworker's approach inefficient. If you need to retrieve the same data from the database several times, why not retrieve it once, store it in session, and remove it once the user is done? Don't database calls affect performance? Is it better to have less database calls and use session scope that is managed properly or is it better to have multiple database calls with the request scope?
Thanks for your opinion.
-PV