• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

How much to use session variables?

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I was wondering if it is any good to use session variables at all. For example when I read from the database I want to be able to read the data in it from other jsp pages.
If I used request..and the user reloaded the page, it will do the query..if I used session i can make a validation so it won't redo the query. And again using session, means I don't have to pass parameters.
Since I have to use JSTL for database operations - I have to- if the operation is not in the same page...then i use a session variable..and after the operation is done..I invalidate the session. Is this good practice?
Thanks
 
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Irrespective of what you have read and done in the arena of 'session' scope,I Would like to say that working with sessions is simply great! Session scope is used to manage the 'state' of web pages useful in managing the login credentials specific to a user.A session expires when- 1.User logs out of website. 2.Web page is closed. 3.Another web site is opened in same tab or window. 4.You forcefully invalidate the session after a specific time. As far as your concern,usability of session depends upon-how many users are going to use your application simultanously?,are you interested in managing a saparate state for all of them at a particular time?,how many pages are going to share the information given in a particular JSP/Servlet?,what should be maximum time for that session/state to be managed?
 
Eman Adenola
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ankit Tripathi wrote:Irrespective of what you have read and done in the arena of 'session' scope,I Would like to say that working with sessions is simply great! Session scope is used to manage the 'state' of web pages useful in managing the login credentials specific to a user.A session expires when- 1.User logs out of website. 2.Web page is closed. 3.Another web site is opened in same tab or window. 4.You forcefully invalidate the session after a specific time. As far as your concern,usability of session depends upon-how many users are going to use your application simultanously?,are you interested in managing a saparate state for all of them at a particular time?,how many pages are going to share the information given in a particular JSP/Servlet?,what should be maximum time for that session/state to be managed?



Yeah, I like sessions too..it makes my life easy..but since I am doing this for an assignment, I am just worrying about the efficiency.
I am not really worried about user scalability but getting addicted to using sessions like a drug..

for example, I have the user searching for a book, so the terms changes..I used request for all this and pass the object to another page to work on. I assume that's fine..
but since you say using session is fine...I shouldn't be too worried then ha.especially as it will be discarded after a timeout
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
>and after the operation is done..I invalidate the session

Why invalidate the session?
Maybe if the user logs out, invalidate it.

Otherwise just keep the user's session around.
If there is data in the session that you no longer need/want then consider removing that attribute via session.removeAttribute or the <c:remove> tag.
 
Eman Adenola
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stefan Evans wrote:>and after the operation is done..I invalidate the session

Why invalidate the session?
Maybe if the user logs out, invalidate it.

Otherwise just keep the user's session around.
If there is data in the session that you no longer need/want then consider removing that attribute via session.removeAttribute or the <c:remove> tag.



Yeah man that's what I meant. I use the c remove tag..I use the session.invalidate() when the user logs out.
I thought c:remove invalidates a specific session variable. I guess that's fine it just removes the data in it..

I need to do some serious read on the stuff lol.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic