| Author |
Can we create more than one session in a Client ?
|
Parthiban Malayandi
Ranch Hand
Joined: Apr 15, 2008
Posts: 67
|
|
Hi all,
I have been learning about sessions . To practice what I have learned I just created a "Number guess" game.
For that game I created three pages
First page is just a static page named index.html which just asks the user name
Second page prompts the maximum number limit to generate a random number between 0 to that number
Third page allows the user to enter the number to guess for randomly picked number
In that game I used user's name as session attribute. Using that attribute if the user enters his name again(user who is not at all finished his game) I just want to display the third page(guessing the number) without again asking the maximum number limit (second page).
It worked fine but it also happens the new user (which is not supposed to do )
So I want to create a NEW SESSION if user is the new one (by checking with existing user name session attribute).
If I used request.getSession(); It just returns the existing session .
Is it possible to create a new session forcefully even if there is an existing session ?
Thanks in advance
|
 |
ujjwal soni
Ranch Hand
Joined: Mar 28, 2007
Posts: 390
|
|
Hi,
It seems that you want to use the same session to store a different value, is it ? If yes then you can invalidate that particular session and reassign a new value to it.
|
Cheers!!!
Ujjwal B Soni <baroda, gujarat, india> <+919909981973>
"Helping hands are better than praying lips......"
|
 |
Deepak Bala
Bartender
Joined: Feb 24, 2006
Posts: 6588
|
|
I am a little confused with your problem description
So I want to create a NEW SESSION if user is the new one (by checking with existing user name session attribute).
New session are created for new users. Are you seeing something different ?
|
SCJP 6 articles - SCJP 5/6 mock exams - SCJP Mocks - SCJP 5 Mock exam (Word document ) - SCJP 5 Mock exam in Java.Inquisition format
|
 |
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12268
|
|
You can always invalidate() the old session and create a new one, but why not just replace the old user information with the new?
There will always be just one session associated with one browser instance because there will only be one session ID cookie.
Read the HttpSession JavaDocs carefully.
Bill
|
Java Resources at www.wbrogden.com
|
 |
Parthiban Malayandi
Ranch Hand
Joined: Apr 15, 2008
Posts: 67
|
|
Hi all ,
Thanks for all replies which helped me to get the concept well.
Actually I don't want to invalidate the session until the user wins the game or intentionally quits the game . That's why in the mean time if
some other user (different user name) sign in I need to keep tracks his records as well as those who didn't win the game till now
Information which I stored as session attribute are follows:
1.His name(which I'm using it great him)
2.Random number picked for him (only once )
3.Maximum limit number
From your replies I understood that only one jsessionid cookie will be available for a browser.
So I changed the game like this :
Once the user log in means another user can't log in (I just redirect to the 3rd page when someone request for first page)until the user quits or win the game(like how GMail works)
Now I feel good and can go ahead to learn further.
Once again thanks for all your replies which really helped me to understand the concept .
|
 |
 |
|
|
subject: Can we create more than one session in a Client ?
|
|
|