如何访问java代码块(jsp文件)中的spring资源包键/值
我正试图从一些我被要求使用的资源包中获取一个键/值对 通常在我们的HTML块(JSP文件中)中,我们可能会有如下内容如何访问java代码块(jsp文件)中的spring资源包键/值,java,spring-mvc,resourcebundle,Java,Spring Mvc,Resourcebundle,我正试图从一些我被要求使用的资源包中获取一个键/值对 通常在我们的HTML块(JSP文件中)中,我们可能会有如下内容 <%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%> <h1><spring:message code="gr.common.title"/></h1> <%@taglib uri="http://www.springframework.
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<h1><spring:message code="gr.common.title"/></h1>
<%@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>
然而,我想在用HTML输出字符串之前用Java处理它,比如
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<h1><spring:message code="gr.common.title"/></h1>
<%@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>
我找到了一个示例,但它似乎位于.java文件或等效文件中您可以使用
core
taglibset
标记
<c:set var="toDoSomeFormat">
<spring:message code="gr.common.title" />
</c:set>
set
元素从其内容中获取其值
然后用
${toDoSomeFormat}
@Nambari使用您的格式。为了清晰起见,我修改了第二段代码,它是一个模型,但我正在尝试实现类似的功能