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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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:
  • 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 ?
 
Ranch Hand
Posts: 783
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Sheriff
Posts: 67748
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Frank, please do not post the same question more than once. Continue any discussion in the original topic.
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic