aspose file tools*
The moose likes JSP and the fly likes HttpSession concept Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "HttpSession concept" Watch "HttpSession concept" New topic
Author

HttpSession concept

Jen Yang
Greenhorn

Joined: Jul 07, 2003
Posts: 11
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

Joined: Feb 26, 2001
Posts: 4738
    
    7

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.


Junilu - [How to Ask Questions] [How to Answer Questions]
Winston Smith
Ranch Hand

Joined: Jun 06, 2003
Posts: 136
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 ]

for (int i = today; i < endOfTime; i++) { code(); }
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4738
    
    7

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

Joined: Jan 10, 2002
Posts: 61424
    
  67

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


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Winston Smith
Ranch Hand

Joined: Jun 06, 2003
Posts: 136
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.
 
 
subject: HttpSession concept