gwt 应用程序客户端的会话管理

发布于 2024-11-02 16:52:42 字数 398 浏览 8 评论 0原文

大家好 我正在开发 gwt-ext 应用程序。在服务器端我使用 Hibernate。 我在服务器端维护会话。超时时间为 5 分钟(在操作类中)。

现在假设一个用户登录并登录的场景。保持打开状态五分钟。五分钟到期后,单击屏幕上的按钮。客户端有一些进程&它是 2 分钟,之后它会进行服务器调用。当它进行服务器调用时,它已经会话结束(因为会话时间是 5 分钟,已经过期)。并且会弹出一条会话结束消息,并重定向登录页面。

在整个案例中,用户感觉我在系统上处于活动状态(实际上在客户端 5 分钟后),所以为什么我被重定向到登录页面。

背后的原因是该会话是在服务器端维护的。服务器命中是在七分钟后。

所以我也在考虑在客户端维护会话。如何在基于 gwt 的应用程序中实现这一点。 有没有其他方法可以解决这个问题。 感谢大家。

Hello All
I am working on the gwt-ext application.On the server side I am using Hibernate.
I am mantaining session on the server side.it's time out is 5 minute (In action class).

Now take a secenario in which a user logged in & remains it open for five minute.After five minutes expires it do a click on a button on the screen.There is some process on the client side & it is of 2 minutes and after that it goes for a server call.When it go for server call it is already session out (as session time is 5 minutes which is already expired).And a message of session out popped up with redirecting the login page.

In this whole case user feels that I am active on the system (After 5 minutes on the client side actually) so why I am redirected to login page.

Reason behind is that that session is maintained on the server side.And server hit is after seven minutes.

So I am thinking to maitain the session on the client side also.How to achieve this in the gwt based application.
Is there any other way to do solve this issue.
Thanks to all.

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

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

发布评论

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

评论(4

╄→承喏 2024-11-09 16:52:42

一种方法是定期检查服务器是否发生超时。您必须编写一个 servlet 方法来执行该检查而不更新服务器会话超时!当然,这会导致大量服务器点击。 (虽然不一定是坏方法!)


但也许我会使用不同的解决方案,它尝试使客户端的计时器与服务器的计时器大致同步,例如

客户端:

import com.google.gwt.user.client.Timer;

public class ClientTimers {

    private static final Timer SESSION_MAY_HAVE_EXPIRED_TIMER = new Timer() {

        @Override
        public void run() {
            // Warn the user, that the session may have expired.
            // You could then show a login dialog, etc...
        }
    };

    public static void renewSessionTimer() {

        // First cancel the previous timer
        SESSION_MAY_HAVE_EXPIRED_TIMER.cancel();

        // Schedule again in 5 minutes (maybe make that configurable?)
        // Actually, let's subtract 10 seconds from that, because our timer
        // won't be synchronized perfectly with the server's timer.
        SESSION_MAY_HAVE_EXPIRED_TIMER.schedule(5 * 60 * 1000 - 10000);
    }
}

我假设您的服务器会话超时每次都会更新客户端与服务器进行交互,例如 GWT-RPC 调用(如果会话尚未超时)。

因此,在客户端,我也会更新客户端计时器,以保持其大致同步:

 myService.performSomeAction(...) {

     @Override
     public void onSuccess(String result) {

          ClientTimers.renewSessionTimer();

          // remaining onSuccess handling
     }

     @Override
     public void onFailure(Throwable caught) {

          if (failedBecauseOfSessionTimeout()) {

              // redirect to login

          } else {

              ClientTimers.renewSessionTimer();

              // remaining onFailure handling...
          }
     }
 }

不要忘记在所有交互中调用 renewSessionTimer() (特别是在登录后直接调用)。

重要说明:对于所有安全检查,仅使用服务器会话。客户端“会话计时器”只是为用户提供方便。不要根据该计时器或任何类型的客户端会话进行安全/授权检查。

One method would be to check the server regularly, if a timeout has occurred. You would have to write a servlet method which performs that check without renewing the server session timeout! And of course this will result in lots of server hits. (Not necessarily a bad method though!)


But maybe I would use a dfifferent solution, which tries to keep a timer on the client side approximately synchronous with the server's timer, e.g.

Client side:

import com.google.gwt.user.client.Timer;

public class ClientTimers {

    private static final Timer SESSION_MAY_HAVE_EXPIRED_TIMER = new Timer() {

        @Override
        public void run() {
            // Warn the user, that the session may have expired.
            // You could then show a login dialog, etc...
        }
    };

    public static void renewSessionTimer() {

        // First cancel the previous timer
        SESSION_MAY_HAVE_EXPIRED_TIMER.cancel();

        // Schedule again in 5 minutes (maybe make that configurable?)
        // Actually, let's subtract 10 seconds from that, because our timer
        // won't be synchronized perfectly with the server's timer.
        SESSION_MAY_HAVE_EXPIRED_TIMER.schedule(5 * 60 * 1000 - 10000);
    }
}

I assume that your server session timeout gets renewed every time the client performs an interaction with the server, e.g. a GWT-RPC call (if the session hasn't timed out already).

So on the client side, I would then also renew the client timer, in order to keep it roughly synchronous:

 myService.performSomeAction(...) {

     @Override
     public void onSuccess(String result) {

          ClientTimers.renewSessionTimer();

          // remaining onSuccess handling
     }

     @Override
     public void onFailure(Throwable caught) {

          if (failedBecauseOfSessionTimeout()) {

              // redirect to login

          } else {

              ClientTimers.renewSessionTimer();

              // remaining onFailure handling...
          }
     }
 }

Don't forget to call renewSessionTimer() on all interactions (especially directly after login).

Important Note: For all security checks, only use the server session. The client "session timer" is just a convenience for the user. Don't make security/authorization checks dependent on that timer, or on any kind of client session.

稚然 2024-11-09 16:52:42

考虑当用户单击屏幕上的按钮时的场景。您可以使服务器命中并检查会话是否处于活动状态。

让我知道我是否了解情况。

Considering your scenario when a user does a click on a button on the screen. You can make a server hit and check whether session is alive or not.

let me know if I have get the situation or not.

入怼 2024-11-09 16:52:42

当超时发生时,此代码将自动注销。对于我的代码,我希望在单击或按下按键时它应该注销。
情况如下:如果用户已登录,注销时间为 5 分钟。根据上述代码,用户现在不在屏幕上进行任何活动,它将在 5 分钟完成后自动注销。

现在我的要求是,如果用户登录并且在 5 分钟内没有执行任何操作。它不应该自动注销。而不是在完成 5 分钟后注销,如果用户在 6 分钟内单击或按下按键那么它应该执行注销过程。

基本上,当计时器超过指定时间时,注销过程应该在用户活动上完成,而不是自动完成。

This code will do log out automatically as the time out occurs.For my code I want that on click or key down it should do logout.
Case is like:If user is logged in and time to log out is 5 min.User don't do any activity on the screen than right now as per the above code it will log out automatically as the 5 min complete.

Now my requirement is that if user logged in and it doesn't do any thing for 5 mins.It should not do any logged out automatically.Instead of logging out on completion of 5 min,If user do click or key down on 6 min then it should do the log out process.

Basically the log out process as the timer exceed the specified time should be done on the user activity, not automatically.

末骤雨初歇 2024-11-09 16:52:42

一定要获取我执行此操作的每个页面事件......它工作正常。

Ext.get("pagePanel").addListener("click", new EventCallback() {
            @Override
            public void execute(EventObject e) {
                //MessageBox.alert("On Mouse Click");
        });

        Ext.get("pagePanel").addListener("keydown", new EventCallback() {

            @Override
            public void execute(EventObject e) { //
                //MessageBox.alert("On Key Press Click");
            }
        });

do get the every page event I have don this....it is working fine.

Ext.get("pagePanel").addListener("click", new EventCallback() {
            @Override
            public void execute(EventObject e) {
                //MessageBox.alert("On Mouse Click");
        });

        Ext.get("pagePanel").addListener("keydown", new EventCallback() {

            @Override
            public void execute(EventObject e) { //
                //MessageBox.alert("On Key Press Click");
            }
        });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文