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

如何访问java代码块(jsp文件)中的spring资源绑定键/值

  •  1
  • Chris  · 技术社区  · 12 年前

    我正试图从一些被要求使用的资源捆绑包中获取密钥/值对

    通常,在我们的HTML块中(在JSP文件中),我们可能会有如下内容

    <%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
    <h1><spring:message code="gr.common.title"/></h1>
    

    然而,在用HTML输出字符串之前,我想用Java对其进行一些处理,比如

    <%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
    <%
    // pseudo below
    String foo = "This is my %s title".format(PSEUDO_MESSAGE("gr.common.title"));
    %>
    <h1><%= foo %></h1>
    

    我找到了 this 示例,但这似乎在.java文件或等效文件中

    1 回复  |  直到 12 年前
        1
  •  2
  •   Sotirios Delimanolis    12 年前

    您可以使用 core 标签库 set 标签

    <c:set var="toDoSomeFormat">
        <spring:message code="gr.common.title" />
    </c:set>
    

    这个 设置 元素从其内容中获取其值。

    然后使用您的格式 ${toDoSomeFormat}