It's not a secret anymore!*
The moose likes Servlets and the fly likes Getting two different sessions in two different tabs of same browser window Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Getting two different sessions in two different tabs of same browser window" Watch "Getting two different sessions in two different tabs of same browser window" New topic
Author

Getting two different sessions in two different tabs of same browser window

Pranav Pal
Ranch Hand

Joined: Nov 04, 2007
Posts: 74
Since two tabs of same browser window share cookies, and session is maintained by embedding session-id in cookies, we get same sessions in two tabs of same browser window.

But is it possible to get two different sessions in two different tabs of same browser window by using some method like encoding URL?


Hakuna Matata!
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Yes, you can use URL encoding.
[ February 07, 2008: Message edited by: David O'Meara ]
S Reddy
Ranch Hand

Joined: May 17, 2007
Posts: 45
But http://meebo.com does allow two sessions with in same window, without URL encoding. How it is possible? Can we do it in Java?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
Two possibilities occur to me:
1. write your own "session" mechanism and use hidden form variables to distinquish between forms in different tabs.
2. generate the contents of each tab from different URLs so the cookie mechanism considers them separate locations.

Bill
S Reddy
Ranch Hand

Joined: May 17, 2007
Posts: 45
Thank you William Brogden.
Tahir Akram
Ranch Hand

Joined: Jul 03, 2007
Posts: 37
Hello Friends;

I need more elaboration towards the solution, that how I can restrict the user if he is accessing my application from another tab.

How can I user URL encoding if this is the solution? and How it helps?
or any other idea to implement it.

--
tahir


Tahir Akram
Tahir Akram
Ranch Hand

Joined: Jul 03, 2007
Posts: 37
Hello Friends;

I have some pointer on the my above problem that how can I identify that user is coming from tab.

if I access session.jsp from index.jsp then on second page I see session.isNew true and Refrer is my index page.

And if I try to open session.jsp directly from another tab then session id will be same, session.isNew false and refrer will be null.

session.jsp




see following cases:

1. User is log in to my site. session.isNew = true and Refere rwill be null (normal case, no action will be taken)
2. User has logged in and browsing my site. session.isNew = false and Refere will not be null (no action)
3. User has already a session and opened a tab and hit the url to login again. session.isNew = false and Refere will be null

in last case I can take action to redirect the user to some messge page that you already login and something like that.

so whats you people think ....
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Getting two different sessions in two different tabs of same browser window
 
Similar Threads
preventing a JSP bean instance from being shared by multiple users
session handling from different tabs of same browser
How to test HttpSessionListener
Is the HttpSession per Tomcat session or per client?
Session