JSTL Format fmt:setBundle Tag

The <fmt:setBundle> tag is used to creates a ResourceBundle and stores the ResourceBundle object into the given variable and scope.

The Syntax Of <fmt:setBundle> Tag

<fmt: setBundle basename= “ResourceBundle Name” var = “var name”/>

Attributes Of <fmt:setBundle> Tag

basenameSpecifies the resource bundle name with the package name.
varSpecifies the variable name to store new ResourceBundle.
scopeThe Scope into which the variable has to be set.


Listing 1: SetBundleExample.java

package javabeat.net;

import java.util.ListResourceBundle;

public class SetBundleExample extends ListResourceBundle {
	public Object[ ][ ] getContents()
		return contents;
	static final Object[ ][ ] contents =
	  		{&quot;girls.sangeeta&quot;, &quot;sangeeta&quot;},
	  		{&quot;girls.mitali&quot;, &quot;mitali&quot;},
	  		{&quot;girls.nisha&quot;, &quot;nisha&quot;},

Details of the Code
ListResourceBundle is used to manage the list of values. The class SetBundleExample extends the ListResourceBundle to get list of values by using getContent method.

Listing 1: example.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<title>setBundle Example</title>

	<fmt:setLocale value="ex" />
	<fmt:setBundle basename="javabeat.net.SetBundleExample" var="lang" />
	<fmt:message key="girls.sangeeta" bundle="${lang}" />
	<br />
	<fmt:message key="girls.mitali" bundle="${lang}" />
	<br />
	<fmt:message key="girls.nisha" bundle="${lang}" />
	<br />


Details of the Code:

  • <%@ taglib uri=”http://java.sun.com/jsp/jstl/fmt” prefix=”fmt” %> tag is used for formatting the data in jsp page.
  • <fmt:setLocale value= “ex”/> sets the locale in the jsp file of the ResourceBundle Class.
  • In setBundle basename we have declared the package name (javabeat.net) and resource bundle name (SetBundleExample).
  • var is used for specifying the variable name.
  • bundle is used to get the value of specified key.

Steps for Execution

  • Save this file as example.jsp in your eclipse IDE.
  • Now select this jsp file, right mouse click and select Run as ->Run on server


When the execution process is completed successfully we will get the following output :
JSTL_fmt setBundle tag_demo

Previous Tutorial : JSTL Format fmt:setLocale Tag :: Next Tutorial : JSTL Format fmt:formatNumber Tag

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Pin It on Pinterest

Share This

Share this post with your friends!

Share This

Share this post with your friends!