简体   繁体   English

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

[英]Http Session Management / Alternative Session Management (in 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. 这些都是用Java完成的。

My client has a SWING based desktop application that will load using WebStart. 我的客户有一个基于SWING的桌面应用程序,它将使用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. 我的朋友建议宁愿使用Http Session Management,因此我决定尝试一下。 I've written a servlet (let's call this SessionServlet) that does create, remove, and reassign sessions based on user profile. 我已经编写了一个servlet(我们将其称为SessionServlet),该servlet会根据用户个人资料创建,删除和重新分配会话。 In tomcat 7, The sessions are not stored. 在tomcat 7中,不存储会话。 I suspect that when the servlet is initialized, the session is blanked out. 我怀疑在初始化servlet时,该会话将被清空。 I only get, org.apache.catalina.ASYNC_SUPPORTED in Session. 我只能在Session中得到org.apache.catalina.ASYNC_SUPPORTED

My question(s) is/are: 我的问题是:

  • How do I allow Tomcat 7 to do Session Management? 如何允许Tomcat 7执行会话管理?
  • How can I do Session Management in Spring 3? 在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. 我的大多数服务都在Spring上运行,我认为在Spring上进行会话管理足够明智。
  • What other means to do Session Management in java, is there a design pattern for Session Management? 用Java还有什么其他方法可以进行会话管理,会话管理是否有一种设计模式? (just curious). (只是好奇)。

Thanks a million! 太感谢了!

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. 我可能会误解您要对会话进行的操作,但是会话(就Servlet而言)仅在用户访问站点时存在。 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? 这是您正在寻找的行为,还是您在访问该网站之间会持续存在的东西?

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. 在进行Http会话管理(尤其是使用Servlet)时,必须确保还存在客户端会话管理。

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. 发生的情况是,在创建会话时,servlet返回一个带有servlet容器创建的Session的JSESSIONID值的cookie。 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. 我不是从我那边存储cookie,因此似乎从未创建过该会话。

Hope this helps someone else. 希望这对其他人有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM