Bookmark Topic Watch Topic
  • New Topic

will sessions mess up with each other on one brwoser  RSS feed

 
Frank Sikuluzu
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • 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 ?
 
Paul Bourdeaux
Ranch Hand
Posts: 783
  • Mark post as helpful
  • send pies
  • 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.

A session technically ends when it is invalidated by the container or when it times out. However, the session ID only lasts on the client for as long as the browser is open. If you quit the browser, then start it up again, you will be in a new 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.

No, it will get the new choice. When you hit submit on JSP1, it will send the current value of the choice parameter to the container. In your example this was 1 the first time and 2 the second time. When you set the "choice" session attribute, it will overwrite any previous values.

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

Yep. Two windows open at the same time are considered to belong to the same session. This can be especially annoying if you are working on a Mac, where "closing" the browser window does not actually "quit" the application...
[ June 22, 2005: Message edited by: Paul Bourdeaux ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
Frank, please do not post the same question more than once. Continue any discussion in the original topic.
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!