【问题标题】:SpringBoot Application: Accessing Common application properties in a JSP pageSpringBoot 应用程序:访问 JSP 页面中的常用应用程序属性
【发布时间】:2016-09-15 22:16:12
【问题描述】:

我正在尝试访问 JSP 页面中 application.properties 中设置的属性。这是出于显示目的,将用户从我们的管理页面发送到不同的应用程序。它根本不需要在代码中。

application.properties 条目:

frontend.url=http://example.com/some_endpoint

在我的 JSP 文件中 我在下面尝试了这些变体。

<spring:eval  expression="('frontend.url')" />
<spring:eval  expression="'frontend.url'" />

下面的这些抛出错误

<spring:eval  expression="@getProperty('frontend.url')" />
<spring:eval  expression="@frontend.url" />
<spring:eval  expression="@applicationProperties.getProperty('frontend.url')" />

是否有特定的语法可以使用,或者我应该只从控制器公开请求属性?

@Value("${frontend.url}")
private String urlForDisplayPurposes;

我知道这里解释的建议方法enter link description here 可以,但我真的不想要额外的属性文件。

【问题讨论】:

    标签: jsp spring-mvc spring-boot jstl spring-el


    【解决方案1】:

    使用@environment.getProperty() 应该可以。例如:

    <spring:eval expression="@environment.getProperty('frontend.url')" var="frontendUrl" />
    <a href="${frontendUrl}">Click</a>
    

    【讨论】:

    • 你必须添加spring taglib到页面:springframework.org/tags" %>
    【解决方案2】:
    <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
    <spring:eval expression="@environment.getProperty('myvar')" var="frontendUrl" />
    

    你可以在jsp中使用“frontendUrl”

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-07-30
      • 2014-08-03
      • 2020-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多