how we can do that when one user is log suuceefully (servlets)
hii to all
first i want to elaborate the scenario
it is like that when one user for example user A HAS USERNAME:ANURAG & PASSWORD: UITK
HE IS ALREADY LOGIN SUCCESSFULLY IN APPLICATION HE SURFING THE WEBSITE.
THEN if another person B TRYING TO LOGIN INTO THE APPLICATION BY THE USE OF THE PERSON A USERNAME AND PASSWORD
then during this i want that person B GET A MESSAGE LIKE THIS "U ARE ALREADY LOGIN " .
MEANS HOW WE ENSURE THAT SEESION MANAGEMENT VERIFY THE UNIQUE USER_ID MEANS NO OTHER CAN BE LOG ON WHEN THAT USERID IS ALREADY LOG IN.
the session because each client will gets unique session and they cannot be cross-checked. You'll either need to keep information in the application context to check against, or perhaps even in the DB.
means let us suppose we has a table current_user
which has field user_id , application_id , session _id ,
and the sessionid is generated from container when user A is login for their user_id and this information is save in this table like this
test , school, jsesso12345 ,
m eans when user is login then we can check it for user_id exist or not in that table but my doubt is that when the second time user is login then this user_id is already exist for same user so how can he will be able to login for the second time .
please suggest me
Re: how we can do that when one user is log suuceefully (servlets)
If I follow, your requirement is that a user can only be logged on one computer at a time.
1) You record the session id in a database when a user logs in.
2) When another client attempts to login with those same credentials the session id's do not match and the connection is refused.
3) The problem as I see it is that when the initial user's session expires the user may not have the same session id when they revisit - thus will not be able to login. To overcome this, look into using an HttpSessionBindingListener, adding it to the session when the user logs in. According to the API this will be fired when the session expires, and can be used to reset the flag in the database.
Re: how we can do that when one user is log suuceefully (servlets)
Well you would probably need another db fields as a timedate
`logged_in` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
select id from table where username='blah' and
(unix_timestamp(now())) time1 ,(unix_timestamp(logged_in)+300)
String id = session.getId();
//get current id - compare this to output of your db - if not found then its a new user.
Also when they log out - before doing log out - to store a status in the same table to say logged_out=1;
But they may close the browser so by checking the session id if the same
Learn Java by Examples - How do I count number of online users?
Have a look here for some more guidance on active sessions.