简体   繁体   English

浏览器关闭并在struts2中重新打开后,保持相同的会话

[英]Maintaining same session after browser closes and reopens in struts2

I am creating one application in struts2. 我正在struts2中创建一个应用程序。

In this I am facing one challenge in session management. 因此,我在会话管理中面临一个挑战。

What I need : 我需要的 :

If user first time open login page in IE browser, then I want to show login.jsp page where user will enter username and password. 如果用户第一次在IE浏览器中打开登录页面,那么我想显示login.jsp页面,用户将在其中输入用户名和密码。 After giving login credentials successfully, I am storing one attribute such as data in session scope using session.setAttribute("data","Hello"); 成功提供登录凭据后,我将使用session.setAttribute("data","Hello");在会话范围中存储一个属性,例如数据session.setAttribute("data","Hello");

Here I am using tomcat persistence JDBC base store. 在这里,我正在使用tomcat持久化JDBC基本存储。 I am able to store session id and it's data in database. 我能够将会话ID及其数据存储在数据库中。

Scenario : Due to some network problem or server problem, we restart the server forcefully. 方案:由于某些网络问题或服务器问题,我们强制重新启动服务器。 At this time may be client can close browser at their side thinking this way that I am already logged in so where I left a page, from that onward my session will start because session is persisted in database using tomcat persistence manager. 此时,客户端可能会以他们已经登录的方式关闭浏览器,以使我已经登录,因此从左边开始我的会话将开始,因为会话是使用tomcat持久性管理器持久保存在数据库中的。

Problem : I am getting the same session with data, if I restart the server but do not close the browser. 问题:如果重新启动服务器但不关闭浏览器,我将获得与数据相同的会话。 And if I close the browser after server restart I am unable to proceed with the existing session. 而且,如果在服务器重新启动后关闭浏览器,则无法继续现有的会话。 Still my database is having the previous session data and when i am trying to display on console i am getting the previous session id but unable to skip login page process. 我的数据库仍然具有先前的会话数据,当我尝试在控制台上显示时,我正在获取先前的会话ID,但无法跳过登录页面过程。

Please help me! 请帮我!

thanks. 谢谢。

To solve your problem you will have to work with persistent cookies. 为了解决您的问题,您将不得不使用持久性cookie。 Persistent cookies are ones which are stored even after the user closes the browser. 永久cookie是即使在用户关闭浏览器后仍会存储的cookie。 The folowing link should be helpful: Using cookies with Struts 2 and Struts 以下链接应该会有所帮助: 在Struts 2和Struts中使用cookie

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

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