aspose file tools*
The moose likes Servlets and the fly likes Can we create more than one session in a Client ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Can we create more than one session in a Client ?" Watch "Can we create more than one session in a Client ?" New topic
Author

Can we create more than one session in a Client ?

Parthiban Malayandi
Ranch Hand

Joined: Apr 15, 2008
Posts: 70
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: 403
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: 6662
    
    5

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 - More SCJP Mocks
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
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

Joined: Apr 15, 2008
Posts: 70
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 .





 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can we create more than one session in a Client ?