简体   繁体   English

Java EE / Struts持久性会话

[英]Java EE / Struts persistent sessions

I'm doing my first Java EE web application and I'm struggling with sessions. 我正在做我的第一个Java EE Web应用程序,并且在会话方面很挣扎。

in my web.xml file I put the following settings: 在我的web.xml文件中,进行以下设置:

<session-config>
  <session-timeout>30</session-timeout>
</session-config>    

But if I close my browser which is not configured to delete cookies on close, after reopen the session is over. 但是,如果我关闭未配置为在关闭时删除cookie的浏览器,则重新打开会话后,会话结束了。

How can I have a "persistent" session ? 我如何进行“持久”会话?

check if a cookie named Jsessionid is getting created during your first request. 检查在您的第一个请求期间是否创建了名为Jsessionid的cookie。 And close your browser open it again and check if that cookie is still there and value is same. 然后关闭浏览器,再次打开它,检查该cookie是否仍然存在并且值是否相同。

I think it will not be, and that is the reason your session expires. 我认为不会,这就是您的会话到期的原因。

When a cookie's expiration is set to "session", it will get deleted by the browser when the user closes the browser. 当cookie的到期时间设置为“会话”时,当用户关闭浏览器时,它将被浏览器删除。 This has nothinng to do with the web.xml session-timeout setting, which will force-close the Java EE session server-side if there are no requests by the user in the designated timespan. 这与web.xml session-timeout设置无关,如果用户在指定时间段内没有请求,它将强制关闭Java EE会话服务器端。

Spring has "remember me" functionality: Spring具有“记住我”功能:

http://static.springsource.org/spring-security/site/docs/3.0.x/reference/remember-me.html http://static.springsource.org/spring-security/site/docs/3.0.x/reference/remember-me.html

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

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