CodesJava

Easy learning with example program codes

JSTL fmt:bundle Formatting Tag

The JSTL <fmt:bundle> Formatting Tag is used to make a specified bundle available for all <fmt:message> tags with its body.

Syntax:

<fmt:bundle basename=”basenameOfBundleResource”  />
      <fmt:message key=”messageKey”/>
</fmt:bundle>

fmt:bundle tag attributes:

AttributeDescriptionRequired
basenameIt specify the base name of the resource bundle that is to be loaded.Yes
prefixIt specify the value to prepend to each key name in subtags.No

Example:

test.jsp

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
 
<html>
	<head>
		<title>fmt:bundle JSTL formatting tag example</title>
	</head>
	<body>
	 <fmt:bundle basename="com.javawithease.properties.message">
	   <fmt:message key="message.first"/><br/>
	   <fmt:message key="message.second"/><br/>
	   <fmt:message key="message.third"/><br/>
	 </fmt:bundle>
	</body>
</html>

message_en_US.properties

message.first = This is first message using en_US locale.
message.second = This is second message en_US locale.
message.third = This is third message en_US locale.

web.xml

<web-app>
 
  <welcome-file-list>
          <welcome-file>test.jsp</welcome-file>
  </welcome-file-list>	
 
</web-app>

Output:

jsp example 47
 
Download this example.
 
Next Topic: JSTL fmt:setBundle Formatting Tag with example.
Previous Topic: JSTL fmt:parseDate Formatting Tag with example.

 

Please follow and like us:
error
Posted in JSP   








Copyright © 2019 CodesJava DMCA.com Protection Status