wood burning stoves 2.0*
The moose likes Servlets and the fly likes Session Attribute Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Reply locked New topic
Author

Session Attribute

Pranav Pal
Ranch Hand

Joined: Nov 04, 2007
Posts: 74
Hello
In my application I set username as a session attribute - 'username'
But when I run the application in two different browser windows,
both windows show same values for the 'username' attribute


Hakuna Matata!
Vassili Vladimir
Ranch Hand

Joined: Mar 08, 2007
Posts: 1585
That's true, because it's the same session

Regards,


Vassili ...
SCJP 5.0, SCWCD 1.4, SCJA 1.0
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

Depending upon which browser you are using and how the browser instances are created, the browser instances may share cookies. Since sessions are maintained by an id value stored as a cookie, this means that any instances that share cokkies will share the session.
[ November 04, 2007: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Pranav Pal
Ranch Hand

Joined: Nov 04, 2007
Posts: 74
Originally posted by Vassili Vladimir:
That's true, because it's the same session

Regards,


Thank you, Vassili
Pranav Pal
Ranch Hand

Joined: Nov 04, 2007
Posts: 74
Originally posted by Bear Bibeault:
Depending upon which browser you are using and how the browser instances are created, the browser instances may share cookies. Since sessions are maintained by an id value stored as a cookie, this means that any instances that share cokkies will share the session.

[ November 04, 2007: Message edited by: Bear Bibeault ]


Thank you, Bear
Pranav Pal
Ranch Hand

Joined: Nov 04, 2007
Posts: 74
Originally posted by Pranav Pal:


Thank you, Bear


How do I assure that browser instances do not share cookies?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

I believe that this primarily a problem with IE. If I recall, when you create a new instance from an existing window (as iwth ctrl-N), the instances will share cookies. If you create a new instance from the Start Menu, no sharing.

Check this before assuming that I'm remembering correctly.
Pranav Pal
Ranch Hand

Joined: Nov 04, 2007
Posts: 74
Originally posted by Bear Bibeault:
I believe that this primarily a problem with IE. If I recall, when you create a new instance from an existing window (as iwth ctrl-N), the instances will share cookies. If you create a new instance from the Start Menu, no sharing.

Check this before assuming that I'm remembering correctly.


Thanks..
If I open a new tab in existing window then only they are sharing cookies..
If I open two different windows then they do not share cookies..

I have another problem..
In a servlet I insert a row in the database
Then I dispatch the request to a jsp
If I refresh the jsp page in browser then the row is again unnecessarily inserted in the databse
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

Originally posted by Pranav Pal:
I have another problem..

Please open a new topic for new questions.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Session Attribute
 
Similar Threads
how can I set multiple attributes to a session object.
how to use session attribute
Is session attribute thread-safe?
Session tracking in servlets
how to get the username from session?