Spring 3-在JSP中访问messages.properties


问题内容

我是使用Spring 3的新手,对此已经停留了一段时间。

您知道如何从jsp访问messages.properties。例如,在控制器中,我为模型设置了一个值:

model.setError("user.not.found")

messages.properties:

user.not.found=Sorry, we haven't been able to found this user

在jsp中,我希望能够

${model.error}

并显示“对不起…”。但是,即使在使用@Valid …,bindingResult然后使用表单时,此方法都可以正常工作,但我始终会得到“
user.not.found”。

谢谢,


问题答案:

<spring:message>springtaglib 使用:

<spring:message code = "${model.error}" />

将taglib导入为

<%@ taglib prefix = "spring" uri = "http://www.springframework.org/tags" %>