aspose file tools*
The moose likes Servlets and the fly likes HttpSession Implementation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "HttpSession Implementation" Watch "HttpSession Implementation" New topic
Author

HttpSession Implementation

sunny ranjan
Greenhorn

Joined: Dec 21, 2012
Posts: 6
can anyone tell me how to implement N sessions for a particular user just using servelets and jsp?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61226
    
  66

Why would a user need more than one session?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
sunny ranjan
Greenhorn

Joined: Dec 21, 2012
Posts: 6
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
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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

Joined: Dec 21, 2012
Posts: 6
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
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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

Joined: Dec 21, 2012
Posts: 6
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
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HttpSession Implementation