Http 会话管理/替代会话管理(Java 中)

发布于 2024-09-15 09:25:47 字数 540 浏览 0 评论 0原文

我会尽力解释我正在做的事情,以获得最佳建议/解决方案。这一切都是用java完成的。

我的客户有一个基于 SWING 的桌面应用程序,将使用 WebStart 加载。我被分配为用户帐户信息创建一个会话管理器。

我的朋友建议使用 Http 会话管理,所以我决定尝试一下。我编写了一个 servlet(我们称之为 SessionServlet),它根据用户配置文件创建、删除和重新分配会话。在 tomcat 7 中,会话不被存储。我怀疑当 servlet 初始化时,会话被清空。我只在会话中得到org.apache.catalina.ASYNC_SUPPORTED

我的问题是:

  • 如何允许 Tomcat 7 进行会话管理?
  • 如何在 Spring 3 中进行会话管理?我的大多数服务都在 Spring 上运行,我认为在 Spring 上进行会话管理对我来说是足够明智的。
  • 在java中进行会话管理还有什么其他方法,是否有会话管理的设计模式? (只是好奇)。

谢谢一百万!

I'll try as best as possible to explain what I'm doing in order to get best possible advice/solution. This is all done in java.

My client has a SWING based desktop application that will load using WebStart. I was assigned to create a Session Manager for user account information.

My friend suggested to rather use Http Session Management, so I've decided to try it out. I've written a servlet (let's call this SessionServlet) that does create, remove, and reassign sessions based on user profile. In tomcat 7, The sessions are not stored. I suspect that when the servlet is initialized, the session is blanked out. I only get, org.apache.catalina.ASYNC_SUPPORTED in Session.

My question(s) is/are:

  • How do I allow Tomcat 7 to do Session Management?
  • How can I do Session Management in Spring 3? I have most services running on Spring and I think it'll be wise enough for me to do Session Management on Spring.
  • What other means to do Session Management in java, is there a design pattern for Session Management? (just curious).

Thanks a million!

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

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

发布评论

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

评论(2

盛夏已如深秋| 2024-09-22 09:25:47

我可能会误解您尝试对会话执行的操作,但会话(就 servlet 而言)仅在用户访问站点时才存在。因此,用户获得第一个页面,并建立一个会话,并且该会话可供用户访问的每个页面使用。当用户离开站点时,会话就会消失。这是您正在寻找的行为还是您正在寻找在两次访问网站之间持续存在的行为?

I may be misunderstanding what you are trying to do with the session, but sessions (in terms of servlets) exist only while the user is accessing the site. So the user gets the first page and a session is set up, and is available to each page the user accesses. When the user leaves the site the session disappears. Is this the behaviour you are looking for or are you looking for something that will persist between visits to the site?

情深已缘浅 2024-09-22 09:25:47

我已经弄清楚了这一点,所以我将分享我的意见。

在进行 Http 会话管理(尤其是使用 Servlet)时,必须确保客户端会话管理也存在。

发生的情况是,当创建会话时,servlet 返回一个 cookie,其中包含 servlet 容器创建的会话的 JSESSIONID 值。确保客户端能够存储会话并在每次需要从服务器访问会话数据时使用它。

我没有从我这边存储 cookie,所以看起来会话从未创建过。

希望这对其他人有帮助。

I've figured this out, so I'll share my input.

When doing Http Session Management (especially with Servlets), one has to make sure that the client-side session management also exists.

What happens is that when a session is created, the servlet returns a cookie with JSESSIONID value of the Session created by the servlet container. Make sure that the client side is able to store the session and use it everytime you need to access your session data from the server.

I wasn't storing the cookie from my side, so it seemed like the session were never created.

Hope this helps someone else.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文