Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Keeping each ID constant

 
Carol Murphy
village idiot
Bartender
Posts: 1202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought I was close to a breakthrough on Servlets 4b when I was able to pass the ID into each page, but now I am having a problem with the ID number being updated to the most recent ID number issued each time a video is added or the see video list button is used. I am testing my code by passing the ID itself into each page. I get a new ID every time I log in, but if I am running 2 or 3 sessions simultaneously, each starts with its own ID, but if I add a new video or update the list, the ID is changed to the most recent ID. Can I stop this from happening? Every solution I've tried doesn't work because I can't figure out to assign each ID to the session that initiated it in such a way that the ID is retrievable by that session only. Any ideas???
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's the way the browser acts. Each time you open a new browser to the same webpage, you are getting a new session, which sort of overwrites your previous sessions. Since your other browsers are still open, the too use the most recent connection, and hence their session becomes the more recent to be opened.
Not sure if this is something you could configure for your browser, or if it is something the webserver might be able to control. I don't think there is anything you would throw into your servlets without getting into looking at connection addresses and all that.
 
Carol Murphy
village idiot
Bartender
Posts: 1202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So theoretically, if I had 2 different browsers installed on the same computer and I opened the videoLogIn page with each browser running at the same time this wouldn't happen? I was hoping it had something to do with opening all of the windows with the same browser, and not crappy code! This is actually encouraging!
 
Marilyn de Queiroz
Sheriff
Posts: 9063
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, if you login using two or three different browsers like Netscape, IE, and Opera, you wouldn't see this problem at all.
 
Greg Harris
Ranch Hand
Posts: 1012
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i was having the same problem... but from 2 different computers.
i have my laptop and desktop networked together. i login from the desktop and add a couple videos. then i login from my laptop and list the videos and add a video. then i list the videos on my desktop.
the first time i login with the laptop i see the new id on the DOS window. when i go back to the desktop i see the old id the first time i change pages... but after that i get the new id created by the laptop.
so, i worked around this in my program... i originally i initialized the "id" outside the method... but now i initialize and pass the id from within the method. is that wrong?
[ March 22, 2002: Message edited by: Greg Harris ]
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it wrong to initialize and pass the id within a method? Heck no, I couldn't think of a better way to do that!
An ID should only be created after the person has logged in AND been validated. Since you are going to need to validate from within a method, it stands to reason that your ID will be generated within that same method (or within a method that is called by the validating method). Either way, you're in a method.
You might have an object that actually holds the data of the token, and pass that object around, but you'd still be setting all of that after the login. Not that I would recommend that.
What it sounds like is you were having an ID created when your servlet is instantiated, correct?
[ March 22, 2002: Message edited by: jason adam ]
 
Carol Murphy
village idiot
Bartender
Posts: 1202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure I'm getting this right, but I put the code for creating the ID inside a method after checking for a valid password. My problem arose when I tried to check my code using different sessions initiated from the same browser. I only have IE ( because that's the one that came installed on my system and I haven't installed a different browser yet because I heard that problems can arise from the browsers fighting for the position of default browser and I don't feel like messing around with any nonsense like that right now.)
Anyhoo, I was going nuts trying to figure out a way to keep the ID number from being updated in each window when I accessed the video list or added a new video, but if it's a browser issue, I feel much better about it!
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take for instance a site that has a counter. If the counter is set so that when someone accesses the site, it counts the number of hits based on the session instead of how many requests for a certain page, then you'll run into this "problem", also.
So I go to a site, and it tells me I am the 14th person to access the site. I hit refresh a couple of times, still tells me I'm number 14, since I haven't opened a new session. Still in the same one. Now I open a new IE browser window, and I go to the same site. My new window tells me I'm number 15. If I refresh the old window, it won't tell me number 14 anymore, it says I'm number 15, also. If I open another browser session, all my browsers refresh to 16, and so on and so on.
You can only control so much in your application. If you plan for just about everything, and someone still does something weird that causes a quirky, but non-critical response, just tell 'em not to do that! Seems to work for the majority of software vendors out there.
 
Carol Murphy
village idiot
Bartender
Posts: 1202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmmm.... I think there may be clue in there for the problem I'm encountering with saving the ID tokens in such a way that I can access the right one for each session.....Thanks!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic