• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Issue in session manegement

 
Ashok Sharma
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I have a problem regarding java session management.
i have created one web application in which i want if user login from one browser instance and opens another instance of same browser and logs in from that then user should be logged out from previous window. I am using Mozzila 5.0.

Here is what i am doing while creating session in LoginServlet.java

session = request.getSession(false); //return session if already exists
System.out.println("Session object: "+session);
if(session != null)
{
System.out.println("Session ID Old: "+session.getId());
session.invalidate(); //invalidate the session if already exists
}
session = request.getSession(true); //Create new session
System.out.println("Session ID New: "+session.getId());

Second and third System.out.println() statements giving the same session id.

This way only the information stored in session when user was logged in from first window is replaced with the new information stored in second window login, but the user is not logged in from the first window though its role is changed suppose in first window he logged in using nornal user login and in second window he logged in as admin user then in first window users role is getting changed to Admin.

Please help me out how i can log the user out from first window if he logs in from second window.

Thanks in advance...
 
Amit Ghorpade
Bartender
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"active ashok" welcome to Javaranch
please check your private messages for an important administrative matter. You can see them by clicking the My Private Messages link above.
 
Amit Ghorpade
Bartender
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is not really a advanced topic.Please choose an appropriate forum for your questions.Asking questions in an unrelated forum yields fewer and less useful response. Read this for more information.

Second and third System.out.println() statements giving the same session id.

Happens sometimes.

Please help me out how i can log the user out from first window if he logs in from second window.

By window do you mean a browser window? Then the problem can be solved if the user has the same browser for this scenario, if he uses two different ones, then things will become messy.
 
Ashok Sharma
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes i mean the browser window, and user is using same browser that is mozzila. User opens one browser window and login as normal user then he opens another window of same browser and login as admin user, then in first window his role gets changed as admin user and the user is not logged out from the first window.
I want to log the user out from first window if he login in another window.
 
Duc Vo
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by active ashok:
Yes i mean the browser window, and user is using same browser that is mozzila. User opens one browser window and login as normal user then he opens another window of same browser and login as admin user, then in first window his role gets changed as admin user and the user is not logged out from the first window.
I want to log the user out from first window if he login in another window.

No, it is not possible. The server doesn't know which window that a request is sent from but only what session that the request represent. Your two windows share the same session hence the effect.

If you want to log in as a normal user and as an administrator, you should open two browser instances/processes (with IE, you can click on the executable twice). If you just use the browser menu to open a new window then it won't work.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64832
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"active ashok", Amit's request that you change your display name to adhere to JavaRanch standards was not a suggestion. Valid display names are mandatory for participation on the Ranch. Please change your display name as instructed prior to your next post.

Be aware that accounts with invalid display names are disabled.

Also, please take the time to choose the correct forum for your posts. This forum is for questions on advanced Java.

For more information, please read this.

This post has been moved to a more appropriate forum.


bear
JavaRanch Sheriff
[ December 10, 2008: Message edited by: Bear Bibeault ]
 
Ashok Sharma
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry! for posting in wrong forum. I will take care of this in future.
I have also changed my display name on forum.
Thanks for your directions
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic