aspose file tools*
The moose likes Servlets and the fly likes Issue in session manegement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Issue in session manegement" Watch "Issue in session manegement" New topic
Author

Issue in session manegement

Ashok Sharma
Greenhorn

Joined: Dec 08, 2008
Posts: 12
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

Joined: Jun 06, 2007
Posts: 2716
    
    6

"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.


SCJP, SCWCD.
|Asking Good Questions|
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

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

Joined: Dec 08, 2008
Posts: 12
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

Joined: Nov 20, 2008
Posts: 254
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.


“Everything should be as simple as it is, but not simpler.” Albert Einstein
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61426
    
  67

"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 ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ashok Sharma
Greenhorn

Joined: Dec 08, 2008
Posts: 12
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Issue in session manegement