Hi,
I am really struggling with this problem.

For ex. I have a login jsp page . After user logs in , I store their username and password in session object in next page.
Now if I want more than 1 user to abe able to login from same browser.
But problem is that As soon as user logs in from 2nd tab, It overwrites the information stored in session object for previous user.

How can i create different session on same browsers. so that different users can work simultaneously .Please help.

<html>
<body>
<form action = "next.jsp">
Name : <input type="text" name="name">
Password:<input type="text" name="password">
</form></body
</html>

next.jsp

<%
session.setAttribute("user",request.getParameter("name"));
session.setAttribute("password",request.getParameter("password"));
%>

Recommended Answers

All 3 Replies

First of all, I don't think it is a good idea to put at the session the password.
Second if you need more than one users then:

session.setAttribute("user_1",request.getParameter("name"));
...
session.setAttribute("user_2",request.getParameter("name"));
...

session.setAttribute("user_"+counter,request.getParameter("name"));
counter++;

The counter could be an int variable also stored in session. Every time a user logs in put his name in the session and increase the counter. Of course you must be careful because if you have session timeout then the counter will become null when you get it from the session. So you need to check that and if it is null set it to 0 again. Besides if that happens then all the users that were logged in will get a timeout so you want miss a thing. They will have to loggin again.

how would you differentiate between requests coming from the 2 tabs?

Yeah i think its not possible to store multiple sessions in same browser.
We can let multiple user login but for rest of personalized pages,how we are going to differentiate.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.