• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to use session

 
Harshit Rastogi
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • 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
 
Veeresh Hosur
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • 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
 
abhishek pendkay
Ranch Hand
Posts: 184
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic