代码之家  ›  专栏  ›  技术社区  ›  martin

Tapestry应用程序中的会话超时AJAX错误

  •  7
  • martin  · 技术社区  · 14 年前

    我知道,这是任何类型的web应用程序(例如。 http://www.openjs.com/articles/ajax/session_timeout.php

    编辑

    Ajax.Responders.register(
    {
        onException: function()
        {
            window.location.reload();
        }
    });
    

    Ajax.Responders 基本上看起来是个好办法。

    3 回复  |  直到 14 年前
        1
  •  5
  •   Henning    14 年前

    对于使用Prototype的AJAX,可以添加一个全局侦听器,该侦听器使用 AJAX.Responders Ajax Events 你可以用的。

    两个事件处理程序都应该重定向到403错误的登录页。你可以创造一个 mixin 并将其添加到布局组件中。

        2
  •  3
  •   iberck    14 年前

    你可以贡献T5主调度员

    
    public class AjaxAccessController implements Dispatcher {
    
        @Override
        public boolean dispatch(Request request, Response response) throws IOException {
    
            // Si no hay session y la petición es ajax, recargar la página
            Session session = request.getSession(false);
            if (session == null && request.isXHR()) {
                OutputStream os = response.getOutputStream("application/json;charset=UTF-8");
                os.write("{\"script\":\"window.location.reload();\"}".getBytes());
                os.flush();
                return true;
            }
    
            return false;
        }
    }
    
    

    在你的应用模块.java

    
    public static void bind(ServiceBinder binder) {
            // binder.bind(MyServiceInterface.class, MyServiceImpl.class);
            // Make bind() calls on the binder object to define most IoC services.
            // Use service builder methods (example below) when the implementation
            // is provided inline, or requires more initialization than simply
            // invoking the constructor.
    
            // Id de AjaxAccessController
            binder.bind(AjaxAccessController.class).withId("AjaxAccessController");
        }
    
    public void contributeMasterDispatcher(
                OrderedConfiguration configuration,
                @InjectService("AjaxAccessController") Dispatcher accessController) {
    
            configuration.add("AjaxAccessController", accessController, "before:ComponentEvent");
        }
    
    

    因此,每个没有会话的ajax请求,页面都将重新加载并重定向到索引页面

        3
  •  0
  •   Nik    14 年前

    好吧,Ajax请求是向服务器发出的,它发送带有“XMLHttpRequest”值的头“HTTP\ux\u REQUESTED\u”。在继续索引页之前,您只需检查服务器端是否是具有上述标题的ajax请求,以及登录和会话超时的条件。

    如果符合您的条件,则只需打印“window.top.location位置.href='login page''在函数中。

    在PHP中,我可以这样做,

    <?php if($_SERVER['HTTP_X_REQUESTED_WITH'] === "XMLHttpRequest" && condition for session check){
        echo "<script>window.top.location.href='login.php'</script>";
        }
    
    ?>