JSTL Format fmt:message Tag

The <fmt: message> tag maps key to localized message to return the value using the resource bundle specified in the bundle attribute.

Syntax Of <fmt: message> Tag

<fmt: message attributes> body content </fmt: message>

Attributes Of <fmt: message> Tag

keyIt is used for specifying the key whose value which we want to display.
bundleSpecifies the resource bundle that is used to get the value of the specified key.
varSpecifies the variable name to store the retrieved message .
scopeThe Scope into which the variable has to be set.


Listing 1:Message .java

package javabeat.net;

import java.util.ListResourceBundle;

public class Message extends ListResourceBundle
	public Object[ ][ ] getContents()
		return contents;
	static final Object[ ][ ] contents =
	  		{"color.blue", "blue"},
	  		{"color.pink", "pink"},
	  		{"color.yellow", "yellow"},

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

Listing 2:example.jsp

<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>


<title>Message tag</title>

<fmt:setBundle basename="javabeat.net.Message" var="lang"/>

<fmt:message key="color.blue" bundle="${lang}"/><br/>
   <fmt:message key="color.pink" bundle="${lang}"/><br/>
  <fmt:message key="color.yellow" 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: message> tag with key attribute is used to display the specified message.
  • 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 :
fmt message tag output


Previous Tutorial : JSTL Format fmt:setTimeZone Tag :: Next Tutorial : JSTL Format fmt:requestEncoding 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!