I have a system that is deployed with the link http://192.168.2.6:8484/DTR
and upon logging in, it stores the user's info via session.setAttribute("user", user);
However, when another user logs in, it overwrites the info of the first user as it again calls session.setAttribute("user", user);
. So how can I really save the user's info so that more than two people can access the system at the same time?
This is what is currently happening:
I have two websites that are open.
first
website (username: user1). Shows Hello, user1
second
website (username: user2). Shows Hello, user2
first
website. It will now show Hello, user2
So how can I enable multiple users to access the website?
You first get user attribute and set it if it's not there and session is new
user = session.getAttribute("user");
if (user == null&& session.isNew())
session.setAttribute("user", user);
Also please check if you are getting different session for different users session.getId() ... if not it might be the problem JSESSIONID cookie. The servletcontainer set a Cookie in the Set-Cookie header of the HTTP response with JSESSIONID as cookie name and the unique session ID as cookie value.
As discussed in the comments, the reason is both the users are logged in from the same browser and same system. So the JSessionId is same and hence the attributes are overriden.
Solution :Try with a different browser
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.