JSTL Format fmt:bundle Tag

The <fmt:bundle> tag is used to create a ResourceBundle object which will be used by its tag body.

Syntax Of <fmt:bundle> Tag

<fmt: bundle basename= “Resource Bundle Name” prefix= “msg”> body content </fmt: bundle>

Attributes Of <fmt:bundle> Tag

  • basename – Specifies the resource bundle name with the package name.
  • prefix – Specifies prefix that has to be used for the message tag used in this element body content.


Listing 1:Simplejstl

package javabeat.net;

import java.util.ListResourceBundle;

public class Simplejstl extends ListResourceBundle {
	public Object[][] getContents() {
		return contents;

	static final Object[][] contents = { { "color.red", "red" },
			{ "color.blue", "blue" }, { "color.pink", "pink" }, };

Details of the Code:

ListResourceBundle is abstract subclass of resource bundle. It is used to manage the list of values. The class Simplejstl extends the ListResourceBundle to get list of values by using getContent method.

Listing 2: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>fmt Bundle Tag</title>

<fmt:bundle basename="javabeat.net.Simplejstl" prefix="color.">
   <fmt:message key="red"/><br/>
   <fmt:message key="blue"/><br/>
  <fmt:message key="pink"/><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.
  • In base name we have declared the package name (javabeat.net) and resource bundle name (Simplejstl).
  • Prefix is used for the message tag used in element body content.

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 :
fmt bundle tag output

Previous Tutorial : JSTL Format Tags :: Next Tutorial : JSTL Format fmt:formatDate Tag

Leave a Reply

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

Pin It on Pinterest

Share This

Share this post with your friends!