Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can we create more than one session in a Client ?

 
Parthiban Malayandi
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Parthiban Malayandi
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 .





 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic