gpt4 book ai didi

playframework - 获取当前加载页面的 URL

转载 作者:行者123 更新时间:2023-12-02 05:06:14 26 4
gpt4 key购买 nike

我问这个问题是因为它与 another 松散相关我的帖子之一。

是否可以在 Play Framework (2.0.4)中检索当前加载页面的 URL?例如,如果我想修改这个方法:

        @Override
public Call afterAuth() {

*IF CURRENT URL = "localhost:9000/mobile"

return routes.Application.mobile_index();

*ELSE*

return something.else;
}

最佳答案

您可以使用 Request获取主机 url 的实例:


public static Result someControllerMethod() {
String uri = request().uri();
if (routes.Application.mobile_index().url().equals(uri)) {
return ok(views.html.mobile_main.render());
} else {
return ok(views.html.index.render());
}
}

其实我不知道你的应用架构细节,但是你可以通过Http.Context到您的登录处理程序。

更新我不熟悉 play-authenticate 模块。我只是查看了这个来源,不知道如何在 Resolver 方法中访问 Http.Context。我只找到了 this question其中提出了一些解决方法,但它看起来不像是一个优雅的解决方案。

关于playframework - 获取当前加载页面的 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16263631/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com