I'm using Spring and JSTL.
I have the following keys in a bundle (messages.properties
):
key.withplaceholder= Never {0}.
key.giveup=give up
And I have the following code:
<fmt:message key="key.withplaceholder">
<fmt:param value="lie"/>
</fmt:message>
With this code I can show the message:
Never lie.
But if I want to use the key.giveup
to show "Never give up"
I don't know how to do it. How can I accomplish this?
Finally, is there a better way to do it? (without having to load a resource bundle in the jsp).
The is used in scenarios where the localized messages are to be personalized or the value to be displayed is dynamic. We can have many parameter placeholders in the resource bundle starting with index 0, we can supply the arguments using tag.
In this post, you will learn how to use the <fmt:message> tag in the JSTL format tags library with code example. The <fmt:message> is used to display the localized messages by replacing the key specified, with the actual message loaded from the resource bundle.
The JSP Standard Tag Library (JSTL) represents a set of tags to simplify the JSP development. Fast Development JSTL provides many tags that simplify the JSP. Code Reusability We can use the JSTL tags on various pages.
There JSTL mainly provides five types of tags: Tag Name Description Core tags The JSTL core tag provide variable suppo ... Function tags The functions tags provide support for s ... Formatting tags The Formatting tags provide support for ... XML tags The XML tags provide flow control, trans ... 1 more rows ...
You can use the var
attribute to store the formatted message in a page scoped variable instead of printing it out to the response.
<fmt:message key="key.giveup" var="key" />
<fmt:message key="key.withplaceholder">
<fmt:param value="${key}" />
</fmt:message>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With