JSTL fmt:setBundle Formatting Tag

The JSTL <fmt:setBundle> Formatting Tag is used to load a resource bundle and set it into the bundle configuration variable.

Syntax:

<fmt:setBundle basename=”basenameOfResourceBundle” var=”varName” />

fmt:setBundle tag attributes:

Attribute Description Required
basename It specify the base name of the resource bundle family to expose as a scoped or configuration variable. Yes
var It specify the name of the variable to store the new bundle. No
scope It specify the scope of the variable to store the new bundle. 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:setBundle JSTL formatting tag example</title>
	</head>
	<body>
	  <fmt:setBundle 
                basename="com.w3spoint.properties.message" var="msg"/>
          <fmt:message key="message.first" bundle="${msg}"/><br/>
	  <fmt:message key="message.second" bundle="${msg}"/><br/>
	  <fmt:message key="message.third" bundle="${msg}"/>
	</body>
</html>

web.xml

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

Output:

jsp example 49
 
Download this example.
 
Next Topic: JSTL fmt:setLocale Formatting Tag with example.
Previous Topic: JSTL fmt:bundle Formatting Tag with example.

 

Please Share