GXT:会话过期时如何带出登录页面

发布于 2024-08-31 13:27:45 字数 140 浏览 3 评论 0原文

我正在使用 GXT、Hibernate、mysql 等开发一个 Web 应用程序。该应用程序有一个登录页面。实际上,我在会话过期时设置登录页面时遇到问题。我们可以在 web.xml 文件中设置超时,但在这种情况下我们无法重定向到登录页面。你能告诉我如何实现这一点吗?

I am developing a web application using GXT, Hibernate, mysql etc. There is a login page for the application. Actually I am getting problem to set the login page when the session expires. We can set the timeout in the web.xml file but in that case we can't redirect to login page.Can you tell me how to achieve that.

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

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

发布评论

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

评论(4

因为看清所以看轻 2024-09-07 13:27:45

您无法执行服务器端重定向,因为应用程序完全是 AJAX。您可以做的是使用 GWT Timer 类,并为每个 RPC 调用检查/重置计时器。如果“会话”过期,则您可以通过历史令牌重定向到登录页面。这对我来说是最简单的方法

其他一些阅读:

http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/b9eab8daaa993c83/d0192d356045e061?pli=1

http://gwt-ext.com/forum/viewtopic.php?f=9&t=1682

You can not do a server side redirect because the application is entirely AJAX. What you can do is use the GWT Timer class and for every one of your RPC calls check/reset the timer. If the "session" expires then you do a redirect to the login page via a History token. This was the easiest way for me

Some other reading:

http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/b9eab8daaa993c83/d0192d356045e061?pli=1

http://gwt-ext.com/forum/viewtopic.php?f=9&t=1682

轻拂→两袖风尘 2024-09-07 13:27:45

我使用了当会话过期时在服务器端抛出异常的概念,然后尝试在客户端捕获异常。我不知道是否有更好的方法可以做到这一点。

I have used the concept of throwing an exception in the server side when the session expires and then tried to catch the exception in the client side. I don't know whether there is any better way to do that.

時窥 2024-09-07 13:27:45

在服务器端,您可以检查会话是否过期,如果过期,则抛出自定义异常。
在客户端,在每个异步调用中,您都会检查此已知情况并对其做出反应。您可以为 AsyncCallback 创建一个抽象类,您将为每个 GWT RPC 调用创建子类:

public abstract class SessionExpiredAwareAsyncCallback<T> implements AsyncCallback<T> {

    @Override
    public void onSuccess(T returnObject) {
        doOnSuccess(returnObject);
    }

    @Override
    public void onFailure(Throwable exception) {
        if (exception instanceof SessionExpiredException) {
            goToLoginPage();
        } else {
            doOnFailure(exception);
        }
    }

    public abstract doOnSuccess(T returnObject);

    public abstract doOnFailure(Throwable exception);
}

On the server side, you can check if the session is expired and if so, throw a custom exception.
On the client side, on every async call you do a check for this known situation and react to it. You can create an abstract class for AsyncCallback that you will subclass for each GWT RPC call:

public abstract class SessionExpiredAwareAsyncCallback<T> implements AsyncCallback<T> {

    @Override
    public void onSuccess(T returnObject) {
        doOnSuccess(returnObject);
    }

    @Override
    public void onFailure(Throwable exception) {
        if (exception instanceof SessionExpiredException) {
            goToLoginPage();
        } else {
            doOnFailure(exception);
        }
    }

    public abstract doOnSuccess(T returnObject);

    public abstract doOnFailure(Throwable exception);
}
断桥再见 2024-09-07 13:27:45

您可以使用 gwteventservice 从服务器向客户端触发事件。

You can use gwteventservice to fire an event from the server to the client.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文