您可以贡献 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;
}
}
在你的 AppModule.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 请求,页面都会重新加载并重定向到您的索引页面