• Post Reply 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

making available a single session at any point of time

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,I want my web application to be accessible by only one client with a given username and password. If another client tries to access the application with the same username and password the previously logged in client should be logged out automatically and his session should be destroyed.
Can any body tell me possible solutions for this problem.FYI this web application is built by using servlets,jsps and the MVC model2 architecture,

Thanks in Advance
[ May 01, 2006: Message edited by: paramesh ande ]
 
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not sure but just guessing...

You must be having a table in database with all the usernames. Add one more boolean column (kind of flag: logged) in that table. Now set this column value to true for users who are logged in. And If another user is trying to login with the same username then check the flag first, if that flag is true (username is already in use) then do action whatever you want (restrict this user or logout previous user).

Any comments??
 
paramesh ande
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually I am able to identify which user is logged in by using a hashtable which is declared as static.If any user logs in I will check the username in the hashtable, if it is there then it can be concluded that some other client is currently using that username.If it is not there i will add the username as an entry into the hashtable.
But the problem is how to invalidate the previous users session.Though I have the previous users request stored in the hashtable i could not use it.
Becoz that is alread responded(flushed), so it is giving null pointer exception.

Any how thank u very much for ur valuble suggession.
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by paramesh ande:
Though I have the previous users request stored in the hashtable i could not use it.Becoz that is alread responded(flushed), so it is giving null pointer exception.



Paramesh, I assume you are using username as key in Hashtable. Then why don't you store corresponding session as value rather than request. Then you will be able to get hold of session object and call invalidate() on it.

Regards,
Jass
 
paramesh ande
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Singh actually I am storing a bean object which holds the request and response objects in the hashtable as value and username as key.
My idea is to send a message to the previous user regarding the new users login for that purpose I preserved the request response objects.But as the response already sent to that user these objects are getting nullified.
So i am not able send the message to the existing user.
As u said if i store the session itself then i can invalidate the session but the message could not be send.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paramesh, I assume you are using username as key in Hashtable. Then why don't you store corresponding session as value rather than request. Then you will be able to get hold of session object and call invalidate() on it.


This is not a good idea as the servlet container is responsible for session management. How would you clean up after sessions that the container has invalidated?
Why do you want to invalidate the already logged in user? Wouldn't it be more logical to tell the 2nd client that the username is already logged in?
Bill
 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Why do you want to invalidate the already logged in user? Wouldn't it be more logical to tell the 2nd client that the username is already logged in?



Assume a scenario:

When a client(user) net connection is gone for some 1 (or) 2 minute and reconnects automatically.User may thought some problem and he clicks logout
(at this time net connection is not available and actual logout not taken place.Session invalidate in server not occur) and user open a new browser and login means he will get message already exists..its not good one in this case???
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic