Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HttpSession concept

 
Jen Yang
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
A newbie question: If a user opens 2 browsers on the same machine, are these browsers share the same session? More specifically, if this user changes a session attribute in one browser, when he clicks "refresh" in the other browser, will he see the change? Thanks.
 
Junilu Lacar
Bartender
Pie
Posts: 7319
45
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do mean windows of the same browser program or windows of two different browser programs?
If you open more than one window in IE they all share the same session. However if you start Netscape and hit the same URL, you'll get another session. I'm not sure if Netscape shares the same session or not between its own multiple windows.
I could be wrong but I think that it all depends on the browser that you're using. Not sure if there's any type of protocol that specifies one way or another.
 
Winston Smith
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Each time you open your browser and go to a URL, that URL assigns a session ID, which is stored on your machine in some manner (cookie, URL rewriting). So, when you open two different browsers, and say, access javaranch.com, the ranch web server assigns each browser a session id, so there are TWO seperate sessions. These sessions are not aware of each other and therefore, cannot share variables.
[ August 29, 2003: Message edited by: Winston Smith ]
[ August 29, 2003: Message edited by: Winston Smith ]
 
Junilu Lacar
Bartender
Pie
Posts: 7319
45
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Winston Smith:
When you open a new browser, a new session is created, so no, you can't share session attributes between browsers.

Well, you can if the session is shared by windows of the same browser program, which IE does. We had to address this problem in our application because the user could open multiple windows and data would "cross over" when he switched back and forth between windows while editing two different records.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It all has to do with cookies. If the browser windows will share cookies, they will share the session. If not, they won't.
Each browser handles this with their own rules, so you need to check what the situation is.
With regards to IE, back when I last checked on this, if another browser window was opened with 'New' or ctrl+N, the new window whould share cookies with the original window. But if a new instance of the pregram was started, they would not share cookies. This behaviour may have changed since last I checked, so try things out on your own to know how things will act for you.
hth,
bear
 
Winston Smith
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Indeed, if one instance of IE spawns another window, session variables can be shared since they will share the cookies.
However, if you open a new instance of IE, they will each have their own session and you won't be able to share session attributes.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic