• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Any faults in this implementation of sessions??

 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actuaaly I am not sure whether I am using sessions in my site correctly.
Wat I am doing is like this...
Whenever user logs in my site with username password I set his session as--
session.setAttribute(sessionname,anyvariable) here anyvariable is usually userid...
and in subsequent pages I extract that session variable as--
String session_name=session.getAttribute(sessionname) and this session_name is that anyvariable that I have set.
And if session_name is not null and session_name is equaly to that userid(in my case) then his session is true...
Well I just want to know does this implementation has any bugs???
 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hai varun,
you can do that.but the thing this since session.getAttribute()returns an object you need to cast it into a string something like this
String session_name=(String)session.getAttribute(sessionname);
and rest of it if fine.
thanks,
jyothsna
 
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Varun,
When the client sends a request first time to the server, it creates and attaches a session to your request with the session id. Each session is identified with the session id. Server maintains each client's session in the form of name-value pairs(Here it is sessionID-SessionObject).
When you call request.getSession(), you will be receiving session object bound to your request by the server. Each time client sends a request to server, session id is also attached to request by cookies, or url rewriting, or in the form of hidden form fields, etc.
You are actually adding attributes to your session. This is possible with session.setAttribute(key, value). As long as your session is alive, you can get the previously set attributes using session.getAttribute(key).
Hope you understood about the session.
Regards,
Ganapathy,S
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic