如何在Struts应用程序中实现注销

发布于 2024-08-11 03:07:44 字数 132 浏览 7 评论 0原文

我有一个 J2EE 应用程序,其注销未正确实现,我的目的是在用户注销后关闭所有数据库资源。不确定 session.invalidate(); 是否有效真的会有帮助,我今天会尝试一下。请建议实现注销的最佳方法是什么,以便用户注销后释放所有有价值的资源。

I have J2EE app on which the logout is not implemented properly, my intention is to close all DB resources once the user logs out. Not sure if session.invalidate(); will really help, I will try it today. Please advice what would be the best to way to implement logout so that all valuable resources are released once user logs out.

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

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

发布评论

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

评论(2

一江春梦 2024-08-18 03:07:44

我的目的是在用户注销后关闭所有数据库资源

这已经是不好的做法的迹象。应该在尽可能短的范围内(即在同一方法块内)获取和关闭数据库资源。您可能永远无法将数据库资源(ConnectionStatement 和/或 ResultSet)作为静态变量或实例变量。这是资源泄漏和更严重的问题的根源。

如果初衷是为了提高连接性能,就需要引入连接池。请记住,这并不是您自己保持联系畅通的借口。只需以同样的方式尽快获取并关闭它们,连接池实现本身就会担心实际关闭连接或将其释放回池。一切都是完全透明的。体面的应用程序服务器附带 JNDI 数据源风格的连接池功能。利用它。完成此操作后,您根本无需担心任何开放的数据库资源或性能。

my intention is to close all DB resources once the user logs out

This is already a sign of a bad practice. The DB resources ought to be acquired and closed in the shortest possible scope, i.e. inside the very same method block. You may never get hold of a DB resource (Connection, Statement and/or ResultSet) as a static or instance variable. It's receipt to resource leaks and more serious trouble.

If the original intent is to improve connecting performance, you need to introduce a connection pool. Keep in mind that this isn't an excuse to keep the connections open yourself. Just acquire and close them as soon as possible the same way, the connection pool implementation itself will worry itself about the actually closing the connection or releasing it back to the pool. It's all fully transparent. Decent application servers ships with connection pooling capabilities in flavor of JNDI datasources. Make use of it. Once done that, you don't need to worry about any open DB resources nor performance at all.

自我难过 2024-08-18 03:07:44

请执行以下操作:

  1. 使用您的连接和其他数据库类来删除数据库资源。
  2. 使用会话对象清除会话。
  3. 检查您在应用程序中创建的 cookie,并删除所需的一个或全部。

Please do as

  1. Use your connection and other database classes to remove the DB resources.
  2. Clear you session using session object.
  3. Check for the cookie you have created in application and remove required one or all.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文