• 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

how to use session

 
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I am new to servlet. I am trying to create an login page. Now i want that everytime a user logs in i should create a session using the user id and reuse it if the user logs in again.

How should i approach for it.

a block of code for this will be a great help
Thanks
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can create Session object by

HttpSession session = request.getSession(true);

If there is session object then the same object will be returned if not a new session object will returned.

Please read servlet api document for more Info.

Thanks
Veeresh
 
Ranch Hand
Posts: 184
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Harshit

Now i want that everytime a user logs in i should create a session using the user id and reuse it if the user logs in again



That is not a good idea... are you trying to say that if a user logs in today you will create a session then the user logs out and does not login again for one week you will keep the session object for one week..???
that is not how a session should be used.. you would be better if you created a new session each time the user logs in
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic