• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

will sessions mess up with each other on one brwoser

 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I heard that session is defined as --- If they are from the same machine within a certain duration of time, the server consider the sessions as the same. Now I am wondering about the following interesting scenarios ---

1. If I have JSP1-->servlet-->JSP2-->servlet-->JSP3, on JSP1 we have five radio button and I pick button 1, in my servlet code I have

***********************
public class Servlet extends ...{

request.getSession().setAttribute("choice", request.getParameter("choice"));

**********************

i.e. I SAVE this choice of JSP1's radio button in the "session" object, then I go to JSP2, I pick button 1 again, then I click "back" which brings me back to JSP1, this time I click button 2 instead, will the server mistakenly think I am still in the "last" session. If this is true, then server will mistakenly pick the "choice" value from last time, i.e. even I pick button 2 this time, the server will get the "choice" value as of button 1's.

2. what if I open two windows on my desktop, will they mess up with each other ?
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Frank Sikuluzu:

2. what if I open two windows on my desktop, will they mess up with each other ?


Here goes....
Maybe.



If you open a second instance of MSIE by typing CTL+N at an open MSIE window, the new instance will share the same session cookie space as the first one. This is also the case if you click "File -> New -> Window" from the menus in MSIE.
Changing a session scoped variable for one screen will change it for both screens.

If, on the other hand, the user opens a new instance by clicking "Start -> All Programs -> MSIE" from the desktop status bar, each instance will have it's own session cookie space and each will maintain a separate session.

This is similar with Mozilla/FireFox. Two tabs in the same instance will share a session cookie. If you open two instances with different profiles each will maintain it's own session.
[ June 21, 2005: Message edited by: Ben Souther ]
 
Frank Sikuluzu
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ben. Actually I am more concerned with the one window scenario like --- If I have JSP1-->Action1-->JSP2-->Action2--->JSP3-->Action3, each Action contains "req" and "res" instances. And while it flows as this, I use session.setAttribute to memorize what I select in each page, now I want to understand this --

1. when I finish JSP1, JSP2, and JSP3 and immediately clikc "back","back" to JSP1 and restart selction from there, at this moment will server create a new session for me or will I get the same session as I just finished with JSP3 ???

2. Following up question, suppose I go through JSP1, JSP2, and JSp3, then immediately click "back" to JSP2 and start picking a different item, will the server immediately give me a new session or what ?

[Bear edit: Bear/Ben, separated at birth?]
[ June 21, 2005: Message edited by: Bear Bibeault ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In both cases you will retain the same session.
You would only have a different session if the original timed out or you explicitly invalidated it.
 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ben Souther:
In both cases you will retain the same session.
You would only have a different session if the original timed out or you explicitly invalidated it.



Although they belong to the SAME session, when you click "back" button and select a different items from what you picked last time, usually in your code you have "session.setAttribute()" to save what you picked and this will override what you stored last time. So you will get the "updated" selection and it doesn't mess up with what you picked last time. I am learning session myself too. Do I make sense here ?

thanks.
 
reply
    Bookmark Topic Watch Topic
  • New Topic