Springboot百里香eaf会议

发布于 2025-02-05 14:24:20 字数 1427 浏览 2 评论 0原文

我有一个Springboot Web应用程序,我正在尝试在同一浏览器上允许并发用户活动。

登录功能具有带有电子邮件和密码属性的成员对象,该属性绑定到胸腺薄层。 当用户登录时,它将显示该用户的信息。

我遇到的问题是,当我在新选项卡中登录第二个用户,而仍以第一个用户登录时,当我向第一个用户添加更改时,用户的详细信息将更改为第二用户。

在Java方面,问题与这一部分有关。

发生的事情是,当我在“数据库”中检查成员是否存在,然后将对象传递给模型时。该模型使用此对象填充字段。

@RequestMapping(method = RequestMethod.POST, path = "/profile")
public String signIn(@ModelAttribute MemberEmail memberEmail, Model model, @RequestHeader, HttpHeaders headers)
    {
        if(MemberDB.validate(memberEmail))
        {
            member = MemberDB.getMember(memberEmail.getEmail());
            model.addAttribute("member", member);
            return "home";
        }
        else
        {
            System.out.println("Login  Failed");
            return "redirect:/devshub";
        }
    }

在我的胸腺中,我有一个功能,用户可以输入消息,并且在其个人资料上显示。

此功能获取消息输入并将其显示在用户配置文件上,但是它也需要一个成员才能再次填充字段,因为

    @RequestMapping(method = RequestMethod.POST, path="/save")
    public String saveMessage(@ModelAttribute Member m, Model model, @RequestHeader HttpHeaders headers)
    {
        member.setMessage(m.getMessage());
        model.addAttribute("member", member);
        return "home";
    }

当我在不同的浏览器上登录到两个不同的帐户时,它返回到“家”,我认为它使用了两个不同的会话ID,每个帐户(通过会话)引用了正确的成员对象。但是,当使用同一浏览器时,当将成员对象设置为第二用户时,如果将消息添加为第一个用户,则添加消息,但将用户信息转换为第二用户。

我认为可能的解决方案可能是重定向而不返回到已经填充用户对象时,但仍在考虑如何做到这一点,因为我最好不喜欢弄乱会话ID。

I have a springboot web application and I am trying allow concurrent user activity on the same browser.

The login function has a member object with email and password attribute tied to a thymeleaf form.
When the user logs in it displays information for that user.

The issue I have is when I log in as a second user in a new tab while still logged in as first user, when i add a change to the first user the details of the user are changed to the second users.

On the java side the issue is related to this part.

What's happening is when a new member signs in I check if the member exists in "database" and then pass the object to the model. The model uses this object to populate the fields.

@RequestMapping(method = RequestMethod.POST, path = "/profile")
public String signIn(@ModelAttribute MemberEmail memberEmail, Model model, @RequestHeader, HttpHeaders headers)
    {
        if(MemberDB.validate(memberEmail))
        {
            member = MemberDB.getMember(memberEmail.getEmail());
            model.addAttribute("member", member);
            return "home";
        }
        else
        {
            System.out.println("Login  Failed");
            return "redirect:/devshub";
        }
    }

In my thymeleaf, I have a function where users can enter a message and it is displayed on their profile.

This function takes the message input and displays it on the users profile but it also needs a member to populate the fields again because it returns to the "home"

    @RequestMapping(method = RequestMethod.POST, path="/save")
    public String saveMessage(@ModelAttribute Member m, Model model, @RequestHeader HttpHeaders headers)
    {
        member.setMessage(m.getMessage());
        model.addAttribute("member", member);
        return "home";
    }

When i log in to two different accounts on different browsers, i think because it uses two different session ids, the correct member object is referenced for each account(by the session). However when using the same browser, when the member object is set to the second user, if i add a message as the first user, the message is added but the user information is switced to second users.

I'm thinking a possible solution could be to redirect without returning to home to when user object is already populated but still thinking of how I could do this as I would preferably not like to mess with session id's.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文