|
Comments
Did you read today's front page stories & breaking news?
SYS-CON.TV
|
AJAXWorld News Desk Rich Internet Applications: Tips, Tricks & Techniques
How to Avoid Multiple Per-User Sessions in Tomcat/JBoss
By: Emanuele Tatti
Feb. 6, 2008 04:15 AM
Usually, in a rich internet application (RIA), a user with a registered account can do two different logins from two different workstations and can maintain two concurrent sessions opened. In some applications we want to limit the users to one session per account, so we have to take countermeasures. If there is no username attribute, we will return an error to the user.
private HashMap hashMap;
public boolean exist(String username) { public MySessionManager() { In our login function we have to check the existence of a previously created session with the same username, in that case we can logout the user associated with that session: if(MySessionManager.getInstance.exist(username)) { In this case the logout function takes as argument a session and log out from our application the user associated with that session, then we can do our login routine and at add the current session to the hashmap. In this example we are checking only for sessions with a username attached, if we want to do some operation every time a session is created/destroyed, we can implement the HttpSessionListener interface: Classes that implement this interface will be notified of session creation and destruction using the respective functions: void sessionCreated(HttpSessionEvent se) To receive notification events, the implementation class must be configured in the deployment descriptor for the web application; for example:
Reader Feedback: Page 1 of 1
Latest Cloud Developer Stories
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
|
SYS-CON Featured Whitepapers
Most Read This Week
Breaking Cloud Computing News
|
|||||||||||||||||||||||||||||||||||||||||||||||||