在JavaScript中替换httpservletrequest.getSession()

发布于 2025-01-30 16:57:05 字数 210 浏览 2 评论 0原文

当前,我们正在使用旧应用程序,其中java httpservletrequest.getsession()函数从浏览器的父级选项卡中设置了会话的客户端浏览器中获取会话。

现在,我们需要访问相同的会话信息[例如,我们在会话中已有令牌] 使用我们的新应用程序与分离的微服务体系结构[UI-REACT JS]。 我们是否能够从前端访问会话?

感谢您对此的建议。

谢谢 !

Currently, we are using a legacy application where the Java HttpServletRequest.GetSession() function to get the session from the Client browser where the session is set from the Browser's parent tab.

Now we need to access the same session information [example, we have Token in the session]
using our new application with decoupled Microservice architecture [ UI-React JS].
Whether we can able to access the session from Front End?

Appreciate your suggestion on this.

Thank you !

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撕心裂肺的伤痛 2025-02-06 16:57:05

HTTP会话是后端的临时商店,您可以根据先前的请求存储东西。一旦您将某些东西存储在此处,后端就会将Set-Cookie标头返回到浏览器,并使用jsessionID浏览器存储给用户。对于下一个呼叫,浏览器将发送相同的jsessionId cookie,后端将其用作检索该用户浏览器先前保存的数据的键。

如果您要迁移到React JS应用程序,我认为无需在后端存储令牌,而是将仅使用JSessionId的Cookie使用。相反,前端可以存储所有必要的数据客户端。

我认为有多种选择:

  1. 将其保持在React状态(在浏览器的内存中)
  2. 将其保存在您通过前端管理的cookie中,
  3. 将其保存在浏览器的LocalStorage中(我认为不太安全)

The HTTP Session is a temporary store in the backend, where you store something based on previous requests. As soon as you store something there, the backend will return a Set-Cookie header to the browser with a JSESSIONID that the browser stores for the user. For the next calls, the browser will send the same JSESSIONID cookie, and the backend will use it as a key to retrieve the previously saved data for that user's browser.

If you're migrating to a React JS application, I think there's no need to store tokens in the backend, and use cookies with only JSESSIONID in. Instead, the frontend can store all the necessary data client-side.

I think there's multiple options:

  1. Keep it in React state (in the browser's memory)
  2. Keep it in a Cookie that you manage via the frontend
  3. Keep it in the browser's localStorage (less secure, I think)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文