【问题标题】:How to get current page url in ftl file如何在 ftl 文件中获取当前页面 url
【发布时间】:2021-06-07 04:09:06
【问题描述】:

我的代码是这样的:

                    <li class="${properties.kcFormSocialAccountListLinkClass!}"><a href="http://localhost:4200/" id="zocial-${p.alias}" class="zocial ${p.providerId}"> <span>Sign in using OTP</span></a></li>
               

问题是,我需要使用 localhost:4200/ 将当前窗口 url 作为查询参数发送。我怎么做 ?该文件是 FTL 类型的。

【问题讨论】:

  • 欢迎来到 Stackoverflow!请发布与分页相关的代码。

标签: angular angular5 keycloak freemarker web-developer-toolbar


【解决方案1】:

这可以通过使用以下方式访问 Servlet Request 对象来实现:

${springMacroRequestContext.requestUri}

如果 ftl 是一个带有 URL http://www.example.com/help 的页面,它将返回/打印 /help 对象springMacroRequestContextRequestContext 类的表示: https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/servlet/support/RequestContext.html

然而,我看到你没有使用 Spring MVC 或 Spring Boot,所以我担心你不能使用它,所以为什么不使用 Javascript 来做呢:

var url = window.location.href;

查看this answer 了解更多选项。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-22
    • 2011-07-15
    • 2017-08-23
    • 2011-06-17
    • 1970-01-01
    相关资源
    最近更新 更多