JSTL - jstl formatting message
<prefix:message> tag ये internationalized message display करने के लिए इस्तेमाल किया जाता है |
Syntax for <prefix:message> tag in JSTL
<prefix:message key="key_name" bundle="bundle_variable" var="variable_name" scope="scope_name"/>
Attributes for <prefix:message> tag in JSTL
key : Optional. यहाँ पर value को display करने के लिए key दी जाती है | यह key resource bundle में से key-value की pair से ली जाती है |
bundle : इस्तेमाल किया जानेवाला resource bundle दिया जाता है |
var : यहाँ पर variable name दिया जाता है |
scope : यहाँ पर scope दिया जाता है |
Example for <prefix:message> Tag in JSTL
Sample.javaindex.jsppackage myPackage; import java.util.ListResourceBundle; public class Sample extends ListResourceBundle { public Object[][] getContents() { return contents; } static final Object[][] contents = { { "myfruit.fruit1", "Mango" }, { "myfruit.fruit2", "Orange" }, }; }
Output :<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> <fmt:message basename="myPackage.Sample" var="fruits" /> <fmt:message key="myfruit.fruit1" bundle="${fruits}" /><br /> <fmt:message key="myfruit.fruit2" bundle="${fruits}" /><br />
Mango Orange
Store Localized Message to Variable in JSTL
<fmt:setBundle basename="myPackage.Sample" var="fruits" /> <fmt:message key="myfruit.fruit1" bundle="${fruits}" var="name1" />${name1}<br /> <fmt:message key="myfruit.fruit2" bundle="${fruits}" var="name2" />${name2}<br />
Mango Orange