Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何访问java代码块(jsp文件)中的spring资源包键/值_Java_Spring Mvc_Resourcebundle - Fatal编程技术网

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

如何访问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.

我正试图从一些我被要求使用的资源包中获取一个键/值对

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

<%@ 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
taglib
set
标记

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

set
元素从其内容中获取其值


然后用
${toDoSomeFormat}

@Nambari使用您的格式。为了清晰起见,我修改了第二段代码,它是一个模型,但我正在尝试实现类似的功能