如何管理用户之间的会话
在index.jsp 中,我有一个徽标,单击该徽标后将转到Admin.java 中的登录功能。我在Admin.java 中进行登录身份验证。工作完成后,使用index.jsp 中的相同徽标进行注销。确实出现了您已注销的消息。
但是,当其他用户尝试登录时,它会使用与前一个用户相同的用户名和密码。
例如,如果 user1 已使用用户名-user1 和密码-user1 登录并注销后。 当另一个用户2尝试登录并输入用户名-用户2和密码-用户2时,系统将参数视为用户名-用户1和密码=用户1。
我如何管理我的会话?我没有使用过cookies。我尝试在互联网上查看代码来帮助我。但我的问题没有通过任何例子得到最好的解释。
问候, 阿卡纳。
In index.jsp I have a logo which when clicked goes to the login functionlaity in Admin.java.I have the login authentication in Admin.java.After the work is done the same logo in index.jsp is used to log out. The message does come you have logged out.
But once again when some other user tries to login it takes the username and password same as the previous user.
Example if user1 has logged in with username-user1 and password-user1 and after log out.
When another user2 tries to login and enters username-user2 and password-user2 the system takes the arguments as username-user1 and password=user1.
How do I manage my sessions? I have not used cookies. I tried to check the codes in internet to help me out. But my problem is not explained best by any example.
Regards,
Archana.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当 bean 是应用程序范围而不是会话范围时,或者当您将用户名/密码声明为静态变量时,就会发生这种情况。这样,它将在所有用户之间共享。
只需将 bean 放入会话范围内,并且不将用户特定的数据分配为静态变量。您也无需担心会话/cookie。 servlet 容器将自行处理这一切并为您完全透明地处理它。另请参阅此答案了解幕后发生的情况。
This can happen when the bean is application scoped instead of session scoped or when you have declared the username/password as static variables. This way it's going to be shared among all users.
Just put bean in session scope and do not assign user-specific data as static variables. You also don't need to worry about sessions/cookies. The servletcontainer will worry about this all itself and handle it fully transparently for you. See also this answer to learn what happens under the covers.
您是否在
Managed Bean
类中实现了 Serialized?喜欢:此外,如果只是登录,我认为您可以使用
Request
范围。你能试试这个吗?
Do you implement Serializable in your
Managed Bean
class? Like:Also, if it's just a login, I think you could use the
Request
scope.Can you try this?