• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HttpSession Implementation

 
sunny ranjan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can anyone tell me how to implement N sessions for a particular user just using servelets and jsp?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why would a user need more than one session?
 
sunny ranjan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what i mean to ask that if a user logs from more than one machine at a time , then how to implement that just using servlets and jsp.
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the user connects to your application from two different browsers, whether they are on the same machine or not, then your application container will automatically assign two different sessions. You don't have to do anything to tell it to do that.
 
sunny ranjan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey paul, i know that but in that case container will treat the user as two different users. but in my case the user is same . my question will be clear through this example
suppose i have my gmail id and i have opened it on my machine . now my friend want to see my gmail at the same time, so i provide him user and password. so at the same instance he also logs into gmail from his own machine. i want to implement this scenario only using servlets and jsp
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, now that you have asked your actual question, then we can answer it.

The solution has very little to do with sessions. You need the user(s) to log in to your application so that they are all accessing the same data. Note that the data used to log in is in a database somewhere, not in the session. Likewise the data they are accessing and sharing is not in the session. The only thing the session is useful for is keeping track of the users' logged-in status.
 
sunny ranjan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks paul, Now the second constraint is that i want a user to restrict for N logins that is if a user , at an instant logs from two machines then it is ok. but i want to restrict him just for the two logins that is if he tries to login from the third machine he should not be able to login. He can only login from third machine only-if one of the current login session is closed.
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay... remember what I said about shared data in the database being the way to control things? You put some shared data in the database to keep track of how many times a user has signed on. Increment it when the user signs on, decrement it when the user signs off.

That's the simple description of the process. In real life you need to take care of more things than that, but it's the general idea.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic